SUM Macro With Variable Ranges

Nov 3, 2006

I cannot seem to get the worksheet function sum to work with varables in this module. It is placing zeros where the summed data should be. The variable are showing proper start and end ranges for summation....

View 5 Replies


ADVERTISEMENT

Variable Ranges For Find() Macro

Jul 11, 2008

Need to pull data from Sheet4 to sheet1 by Sales Person based on a validation list cell on sheet1.

Each Sales person has a different number of accounts listed on Sheet4. The data is setup like this (my apologies for not knowing how to copy and paste the data)

Will Use Jane Doe and John Smith As examples-

A1, Jane Doe, Customer Name, Data, Data, Data, etc.
A2, Jane Doe, Customer Name, Data, Data, Data, etc.
A3, John Smith, Customer Name, Data, Data, Data, etc.

So Jane Doe has 2 customers total, and John Smith has 1 customer.

I am dealing with a total of 300+ Sales People and over 4,000 customers, all with a different number of customers per sales person.

How in the world can I write a code that will pull all of Jane Doe's customers when she is chosen from the validation list, and paste those customers and their coinciding data where I need it to paste?

I have the validation list working, so all I need at this point is help with the copy/paste code.

View 9 Replies View Related

Macro: Copy And Pasting Variable Ranges On Seperate Sheets

Nov 4, 2009

I have attached the xls. I have an input sheet with 3 columns to enter data. Each column is linked to a separate worksheet with a formula (Carrys 1000 rows long). I need to be able to pull the populated data from those 3 worksheets and paste into 1 column continuously on another worksheet so all data is on top of another without any spaces.

I made an if statement so that if there isn't data pulling from the input sheet the a blank cell is left to indicate the last row to copy data from and paste on the final sheet.

View 5 Replies View Related

Sum Of Variable Length Ranges?

Jun 20, 2014

So I have got an identifier and a corresponding column of values. I need to calculate sum of those corresponding values for each identifier, so if identifier is 1993, I need to have a sum of all the corresponding values. These identifiers repeat, and I do not want to calculate sum for all of them, just the immediate identifiers (i.e. you have 1993, after that you may have 1994 etc etc and then at one point you will have 1993 again, but that "new" 1993 will have a different sum of course). Also, identifiers do not go in sequence sometimes (however, most of the case they do), for example 1993 may jump suddenly to 2004. The trick with all of this is variable "row width" of these identifiers...

222.xlsm

View 13 Replies View Related

Dynamically Variable Ranges

Dec 31, 2006

In my worksheet cell A1 represents a financial reporting period from 1 to 12. It also represents the number of columns I need to sum in order to arrive at the desired period totals in this income statement worksheet. How can I get Excel to automatically change my SUMPRODUCT function as the value in cell A1 is changed from 1 to 12?

Here is a sample cell formula:

=SUMPRODUCT(ISNUMBER(MATCH(GL1SHL.XLS!$A$2:$A$332, {"4620","5220"},0))*(GL1SHL.XLS!$CE$2:$CE$332)*(GL1SHL.XLS!$I$2:$T$332))

The above formula represents the totals for period 12 for General Ledger accounts 4620 and 5220.

GL1SHL.XLS! references the workbook that has the financial data exported from my G/L application.

$A$2:$A$332 is the column which contains the G/L account number to be matched.

$CE$2:$CE$332 references a cell that resolves to the value 1 or -1 so that expenses which are exported as positive values become negative.

$I$2:$T$332 represents the 12 columns and 332 rows that contain all the financial data necessary to calculate the income for period 12 with each row representing a different G/L account's 12 periods of financial data. I need a method to dynamically replace the 'T' in $I$2:$T$332 and resolve it based on the value in cell A1. So if A1=1 then 'T' becomes 'I' and if A1=2 then 'T' becomes 'J' etc.

I would like to do this as a macro substitution instead of having to make 12 worksheets, one for each period, or instead of having 12 nested loops.

View 12 Replies View Related

Variable Vlookup Ranges

May 8, 2008

I have an Excel File with 2 worksheets.

Sheet1 contains column A as "Product Number", Column B as "Product Family". Rows contain about 20,000 lines of data. A Range has been created to cover both columns, and named "ProdRange"

Sheet2 contains Column A (blank), Column B with "Product Number"

What I am trying to do is start at the top of Sheet 2 "Product Number" (B2 is first cell ref), and use this value to do a Vlookup on Sheet 1, to extract the "Product Family" code on the Offset 1 - and insert it back into Sheet 2 Column A.

I have this below :

For i = 2 To LastRow
Range("A" & i).Value = "=VLookup("B" & i, ProdRange, 2)"
Next i

BUT for some reason it doesn't like the [ "B" & i ] part of the equation.

View 9 Replies View Related

Variable Cell Ranges In Formulas

Feb 23, 2008

I need to run a formula each month which calculates the ‘product’ for a range of cells in a column, where the cell range will change each month. The starting cell for the range is static, but the range end will always change - additionally, the last valid cell will always be followed by a null value cell. The attached example shows the basic format of my data – a range of values, by row, which will always end with a null value cell. The formula I’m using (to match my example) is: =(PRODUCT(A10:A13) –-> and I want to display the result in cell C10.

While I’ve been able to identify the ‘ending good row’ several ways, I haven’t been able to figure out what to do with this information – I seem be be lost in the translation of OFFSET values to CELL REFERENCE values. Has anyone encountered this specific scenario and found a solution?

View 3 Replies View Related

Summing Amounts Corresponding To Variable Date Ranges

Oct 25, 2007

Need formula which can sum Amounts from varying Weekly time periods and the result be recorded in the appropriate month? I've attached a simple example of the way the output needs to look and a sample data table below.

View 3 Replies View Related

Append Variable Based On Date Ranges?

Oct 10, 2013

I have a reference dataset that looks like:

Adweek Start_Date End_Date
201201 05-Jan-12 11-Jan-12
201202 12-Jan-12 18-Jan-12
...

In the dataset I would like to merge the variabe Adweek, looks like:
Date Sales
05-Jan-12 $100
06-Jan-12 $110
...
15-Jan-12 $150
...

I'd like to get to here:

Date Sales Adweek
05-Jan-12 $100 201201
06-Jan-12 $110 201201
...
15-Jan-12 $150 201202
...

View 2 Replies View Related

VBA Code For Printing Variable Print Ranges

May 5, 2009

I am trying to write VBA code that will print a print range that is presented in cell F3 on a "Reports" worksheet. The content of F3 will change depending on how many reports the user selects to print. For example, he could select one, two, three reports etc - up to twelve. The cell ranges of each report are named (e.g. Report1, Report2 etc) so that if the user selects to print Reports 1 and 2, the contents of cell F3 are "Report1,Report2". If I replace WhatToPrint with "Report1,Report2" the print macro works.

Sub Macro2()
Dim WhatToPrint As String
WhatToPrint = Sheets("Reports").Cells(3, 6).Value
'sets the variable to equal the contents of cell D3 which contains the formula
'summarising the print ranges I want to print
Sheets("Reports").Cells(3, 6).Select
ActiveCell.FormulaR1C1 = WhatToPrint
' pastes the variable in cell F3 - just to check that it looks like I want it to
Sheets("Reports").PageSetup.PrintArea = WhatToPrint
'uses the variable to set print area - this is where it fails!
'if you replace the variable with the contents of cell F3 the macro will work
ActiveWindow.SelectedSheets.PrintPreview
End Sub

View 3 Replies View Related

Setting Column Chart Data Using VBA For Variable Ranges

Mar 10, 2014

I have some code to plot a column chart of data but it isn't working as expecting at the moment. The code is below. The variable binCounter is a count of how many cells in a range that I want to plot on the chart.

However, what I am finding is that the first couple of cells in the range appear as the series name with the rest appearing as the data in the chart. Secondly, the chart appears with the axis labels 1,2,3 etc when I have some custom ones I would prefer to use. How do I go about setting this property, as I can only find options on setting the axis title There is a lot of stuff on XY charts on Google but I can't find much on column charts unfortunately .

VB:
'activate sheet and chart
Worksheets("Home Page").Activate
ActiveSheet.ChartObjects("Histogram").Activate

'set variables for chart
With ActiveChart

[Code] .....

View 1 Replies View Related

Indirect Referral To Variable Size Named Ranges

Feb 13, 2007

I am trying to use a combination of dependent named ranges and variable length ranges, so one can select in eg Col A truck name from a drop down list, and then in Col B, the engine variant only for that make of truck. The indirect(substitute) function works well if I define the dependent range name (the engine variant) using actual cell refs. However if I use the variable length name definition as described in Ozgrid (ie with offset function), I get an error message and the dropdown menu freezes. Is there anyway to overcome this without resorting to VBA?

View 4 Replies View Related

2007 Macro: Run-time Error 91:Object Variable Or With Block Variable Not Set

Feb 20, 2009

I'm fairly new to macro's and VBA, by searching on the internet i've copied and pasted some code together into a macro.
But it ends in a Run-time error 91...

The macro opens a target .xls file in a selected folder, performs copy - paste actions from masterfile to targetfile.
Than it filters data in the targetfile sheet1 and copy's the results to the various other sheets; saves and closes the targetfile.
The next target file in the folder is opened and the actions are repeated in this second target file.
For the first target file this works smoothly; but for the second one (of a total of around 100) it does not copy the filter results to the other sheets in this workbook.
The error message i get is: "Run-time error 91:Object variable or with block variable not set."
When i hit debug it highlights the line "ActiveSheet.Next.Select" which, at least in the first file, seems ok.

View 9 Replies View Related

Updating Values In Variable Ranges Based On Repeating Patterns In A Column

Jul 6, 2006

I have a list of two columns. Here’s an example. The left most column provides the row number.

_ A B
1 1 0
2 2 1
3 2 1
4 3 2
5 4 2.5
6 5 4
7 1 0
8 1 0
9 2 2

Whenever there are two repeating numbers in column one, I want to reduce certain numbers in column 2 by a certain amount. The amount is determined by half the difference between the number in column B corresponding to the second repeated number and the number in column B corresponding to the row after the second repeating number. The range of numbers that are to be reduced begins with the row after the second repeating number and ends with the last row before number one appears in column A. The values in column A are integers, always starting with one. For example, 1, 2, 3, 4, 1, 2, 3, 1, 2, 3, 4, 5.

For the above example, after finding the repeating number two’s at A2 and A3, it would reduce B4 through B6 by half the difference between B3 and B4 (1/2). The values for B4 through B6 would be updated in column B. The same for the next repeated numbers, which is one at A7 and A8. Half the difference between B8 and B9 is 1.

Here’s what the updated list would look like:

1 1 0
2 2 1
3 2 1
4 3 1.5
5 4 2
6 5 3.5
7 1 0
8 1 0
9 2 1

View 9 Replies View Related

Macro Error Message (object Variable Or With Block Variable Not Set)

Jul 7, 2009

When i try to run the code below i get the error message - object variable or with block variable not set-

Sub REFRESHXX()

'LIST
Cells(Sheets("POINTS").Range("DD801").Value, Sheets("POINTS").Range("DD800").Value).Select
Selection.AutoFilter Field:=1, Criteria1:="1"
'SET RANGE
Dim sFormula1 As String
Dim sFormula2 As String
Dim sCell1 As String
Dim sCell2 As String
Dim sSheet1 As String
Dim sSheet2 As String
Dim r As Range
Dim MyRange As Range 'for testing

With Sheets("Points")
sFormula1 = .Range("CY1").Formula
sFormula2 = .Range("CY2").Formula
End With

'FORMULA IN R1C1 STYLE
strFormula = "=IF(ISNA(VLOOKUP(RC[-1],MASTER!R4C3:R17908C7,3,FALSE)),0,VLOOKUP(RC[-1],MASTER!R4C3:R17908C7,3,FALSE))"
'ENTER FORMULA IN ALL CELL RANGES
r.FormulaR1C1 = strFormula
'REDUCE TO VALUES
Dim ar As Range 'an area is a range
For Each ar In r.Areas 'areas are discrete, contiguous ranges of cells
ar.Value = ar.Value
Next ar

'UNLIST
Cells(Sheets("POINTS").Range("DD801").Value, Sheets("POINTS").Range("DD800").Value).Select
Selection.AutoFilter Field:=1

End Sub

View 9 Replies View Related

Find Dates Macro: Object Variable With Block Variable Not Set

Nov 21, 2006

I found this nice little bit of code for a date range search in column A but it will not work. Apparently i have not set a variable or something.


Private Sub Worksheet_SelectionChange(ByVal Target As Range)

Dim startDate As String
Dim stopDate As String
Dim startRow As Integer
Dim stopRow As Integer
startDate = InputBox("Enter the Start Date: (dd/mm/yyyy)")
If startDate = "" Then End
stopDate = InputBox("Enter the Stop Date: (dd/mm/yyyy)")
If stopDate = "" Then End
startDate = Format(startDate, "dd/mm/yyyy")
stopDate = Format(stopDate, "dd/mm/yyyy")
startRow = Worksheets("sheet1").Columns("A").Find(startDate, _
LookIn:=xlValues, lookat:=xlWhole).Row
stopRow = Worksheets("sheet1").Columns("A").Find(stopDate, _
LookIn:=xlValues, lookat:=xlWhole).Row
Worksheets("Sheet1").Range("A" & startRow & ":A" & stopRow).Select

End Sub

View 9 Replies View Related

Conditional Copying - Variable Ranges - Sprint Cell Phone Usage Import

Nov 30, 2008

I am working on a project to import cellular phone usage data from Sprint into a workbook.

All cells in Column A are blank. Column B contains 1 instance of the cell phone account #, followed by dates of calls made, which continues until the next cell phone account # appears, and it’s calls made. The # of calls made obviously varies per account #.

The dates are in date format. The cell phone account # is in text format and is formatted with blue fill.

I need to copy the cell phone account # into column A for each line that has a date value in ColumnB, but the value copied must change when it reaches the next cell phone account #, so that the calls are matched up with the cell phone account # and can be imported into SQL.

Acct #
Date
Time
City Called from
State Called From
Called #
City Called
State Called................

View 17 Replies View Related

Object Variable Or With Block Variable Not Set Error With Macro

Mar 12, 2009

I attempted to modify "macro_1a1ay" to look into the "comments" sheet (column a) for a specific text string. If that text string is found, I have it delete the entire row, then re-sort the page and return to the calling page. It works well as long as it finds something. When it does not find the string (i.e. like now when the page is blank) it gives me the run-time error mentioned above.

View 7 Replies View Related

Macro Sum Everything Between These Two Ranges

Mar 6, 2007

I have two reference points "start_calc and end_calc" and I'm trying to figure out what the coding is in the a macro to sum everything between these two ranges.

In case that's not clear, say reference point #1 is A1 and reference point #2 is A26. in A27 I want to the Sum of A1 to A26. But the next time the macro runs the data points migh be A1 to A27 and so on.

This is why I'm usind start_calc and end_calc references rather than specific cells.

View 9 Replies View Related

Using Same Macro To Sum Changing Ranges

Jul 21, 2014

Is it possible to use the same macro when ranges have been changed? Attached is a sheet that I update frequently (rows will change day to day, not columns) and the goal is to have a dynamic macro that sums the rows highlighted in yellow and red. Is this possible?,

View 4 Replies View Related

Macro For Two Named Ranges

Feb 24, 2009

Macro for two named ranges. I have this code, which works fine...

View 4 Replies View Related

Macro To Automatically Name Ranges?

Jun 29, 2012

I have a sheet containing employee data - 13,000 rows - one for each employee.

Column A contains their store number (there are about 1300 stores in total) and column H contains their name.

Is it possible to create a macro that, for each change in store number, will create a named range for the employees' names in that store automatically?

View 9 Replies View Related

Macro To Loop Over RANGES

Aug 3, 2012

I have a table sorted on column A. I need a macro to go row by row on that list and stop when the NAME (column A) is changed, in this example 3 first rows "aa". then I need to define the range of these 3 rows (A2:D4) in the table and make some subroutine. After finishing with this range I need the macro to continue and find the next rows with the same name, define the Range and go to the subroutine (in my example A5:D5)

The next range will be A6:D7 and so on until last range A27:D27. How can it be done?

I tried some CASE, FOR NEXT, DO UNTIL loops to do this but get stuck.

DATA *ABCD1NAMEDATEALERTTEST
2aa10HB3aa20INR4aa41WBC5ww50ELE6zz30DIG7zz61HYD8dd21CRE9dd41PLT10dd60HB11dd71INR1
2rr10WBC13tt20ELE14tt41DIG15yy40HYD16uu51CRE17ii20PLT18ii31HB19ii51INR20ii70WBC21ii80
ELE22oo20DIG23ll11HYD24ll20CRE25ll30PLT26mm21HB27nn30INR

View 7 Replies View Related

Changing Ranges In A Macro?

Jun 24, 2013

Code:

Sub appointment_nieuw()
With CreateObject("Outlook.Application").CreateItem(1)
.Subject = Range("C3")
.Start = DateValue(Range("A3")) + TimeValue(Range("B3"))
.Duration = 0
.Location = Range("D3")
Dim cell As Range
For Each cell In Range("F2:H2")
.body = .body & Space(2) & cell
Next
.Save
End With
End Sub

I have this macro that works great, but every time I have a different appointment. I have to go into VB editor and change the ranges for the subject, datevalue, timevalue, location and body.

Can I get a text box (or something better) to pop up and I enter the ranges for the 5 in it and have it change in the macro?

View 6 Replies View Related

Macro To Name Tons Of Ranges

Mar 29, 2007

i have a workbook with about 32 sheets (number of days in the month, plus index page). each sheet has info on mutliple shows, i was wondering if there was a macro that i could use to go to Sheet 2 (first day of the month) selecet B10:B200 and name it date1, move to the next sheet name it date2, and so forth, through the end of the book.. then go back to sheet 2 select the next 4 columns rows 10 through 200 (in this case, C10:F200), name it Show1Date1 move to the next sheet and name the rance Show1Date2, then go back to sheet 2 and do it again ie G10:J200 named Show2Date1, next sheet is Show2Date2.... and so forth until we hit the end of the workbook at Show30Date(either 28, 30 or 31 obviously)....

View 9 Replies View Related

Sum 2 Ranges By Condition Macro

Oct 22, 2007

how to properly use the OR operator.

Currently, I have the following code in my program:

Cobbs = WorksheetFunction. SumIf(Sheet5. Range("H9:H500"), "C/F", Sheet5.Range("I9:I500")) _
+ WorksheetFunction.SumIf(Sheet5.Range("H9:H500"), "4/F", Sheet5.Range("I9:I500"))

But it seems to me that the program should work just fine if I use something like this shorter line of

Cobbs = WorksheetFunction.SumIf(Sheet5.Range("H9:H500"), "4/F" Or "C/F", Sheet5.Range("I9:I500"))

But it just ain't working for me. Can the OR operator not work in this situation? If so, what is the proper syntax?

View 3 Replies View Related

Macro To Compare Two Ranges In Two Different Sheets

Apr 17, 2014

I am relatively new to VBA macros. I am having two sheets, in one sheet I have a non-contiguous 20 rows range and in the other sheet I have a 20 row contiguous range. I need a macro which will compare data between the two ranges(one to one compare) meaning 1st row of the first range should compare with 1st row of the second range and if it matches then it should populate the adjacent column in the second sheet with true or false accordingly.

View 2 Replies View Related

Editing Macro To Allow Dynamic Ranges?

Oct 31, 2011

having trouble editing the code to allow for dynamic ranges. I have tried to research online, but am having a hard time with it. I think I would understand better if I could see a practical example.

Here is the sample macro I recorded in Excel that I am working with:

Sub Macro1()
'
' Macro1 Macro
'
'
Cells.Select
ActiveSheet.Range("$A$1:$C$87").RemoveDuplicates Columns:=Array(1, 2, 3), _
Header:=xlNo
End Sub

How can I edit this to allow for dynamic rows and columns?

View 2 Replies View Related

Selecting Dynamic Ranges In Macro?

Nov 30, 2011

I run a macro on a spreadheet in which the rows increase daily. In the macro I simply recorded an end.down to select a column of data which ends up being fixed row numbers in the code so the next time I run the macro it only selects the range I selected last time.

View 1 Replies View Related

Getting Macro To Work On Several Ranges On Same Sheet

Jun 24, 2014

I have the following Macro:

Code:

Private Sub Worksheet_Change(ByVal Target As Range) ' Code goes in the Worksheet specific module
Dim rng As Range
' Set Target Range, i.e. Range("A1, B2, C3"), or Range("A1:B3")
Set rng = Target.Parent.Range("C13:D25")
' Only look at single cell changes
If Target.Count > 1 Then Exit Sub
' Only look at that range
If Intersect(Target, rng) Is Nothing Then Exit Sub

[code]....

Which does not allow entry to range C13:D25 if D12 is empty. Works great!But I need it to work across ranges E13:F25 if F12 is empty, G13:H25 if G12 is empty etc.

I tried copy pasting the same macro over and over again but renaming it to e.g. Worksheet_Change2 causes the Macro to stop working completely.What am I doing wrong?

View 5 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved