Formula Sum Variable Range
Jan 17, 2012
I am trying place the "sum" formula into multiple cells, changing with "i" (itteration process).
Something like:
.Range(17,counter).formula = "=Sum(B2:B20)"
when the couter itterates, the same line of code should give:
.Range(17,counter).formula = "=Sum(F2:F20)"
My actual code looks like: ... which doesnt work.
.Offset(17, " & ColumnHeadCout & " + 1).FormulaR18C" & ColumnHeadCout + 1 & " = ""=SUM(R[20]C[" & ColumnHeadCout + 1 & "]:R[" & NumberStreamElem + 20 & "]C[" & ColumnHeadCout + 1 & "])"
View 9 Replies
ADVERTISEMENT
Jul 6, 2007
I have below code (option 1) I was hoping would do what I need except instead of copying formula from A1 it copies values... (option 2) copies formula but does not preserve references...any ideas how to copy exact formula so that references are not changed?
Assumptions:
A1 formula = SUM(B2:E2)
in A5 I would like to copy exact formula to keep references to row 2...
I agree I could use $ in original formula but that would complicate other requirements.
OPTION1:________________
Sub test_var_object()
Dim vRange1 As Range
Set vRange1 = Range("A1")
Range("A5") = vRange1
End Sub
OPTION2:________________
Sub test_var_object()
Dim vRange1 As Range
Set vRange1 = Range("A1")
vRange1.Copy
Range("A5").PasteSpecial
End Sub
View 9 Replies
View Related
Aug 9, 2007
I've developed a code to load csv files in excel and do some formatting on it. In addition I want to add a few cells which calculate making use of the data in the file. The data tabel (resulting after the csv import) always has the same number of columns, but the number of rows varies depending on the imported file.
My problem now is that I need to change the formula for my calculation depending on this number of rows.
This is what I got so far (not including the csv import):
Option Explicit
Dim varRow As Double
Function fctCountNrRows() As Double
Range("A1").End(xlDown).Select
varRow = Selection.Row
End Function
Sub subAddTotals()
fctCountNrRows
Cells(varRow + 2, 1).Select ..............
View 9 Replies
View Related
Oct 3, 2007
I have an excel based report where I drop data into a blank spreadsheet each month and my formula (in a second worksheet) finds the relevant information. I do this by using the Match function on the first row of my source data. This finds the column numbers to the data I am interested in. (This is handy as additional columns of data appear almost every month). Most of my formula (in the second worksheet) works on vlookups using the column number from the match function.
However, I need to do a sumif. Sumif requires cell references rather than a column number. How can I get around this? Due to the nature of the report, VBA isn't appropriate in this instance. I'm only producing the initial report; someone else will be updating it each month.
View 2 Replies
View Related
Nov 27, 2007
It is useful to use lookup function to find the student name. However, if the table array size is variable
(say, a new student enrolled and the table array will be $A$2:$B$7), the table array size will be changed
and we need to change the vlookup function. How to avoid it? Can we use some kind of variable for the
See attached file( book1)
View 9 Replies
View Related
Mar 12, 2008
How do I pass MATCH or COUNTIF the current dynamic row instead of hardcoding $3? The column is fine hardcoded. Column F has data validation allow List with source equal to dynamic range "userlocation". Column H has data validation allow List with source =OFFSET(userlocation,MATCH($F$3,userlocation,0)-1,1,COUNTIF(userlocation,$F$3),1)
In Column H, this will in effect provide me with a list of values based upon the value of cell F3. Problem is I can't seem to figure out how to reference ROW as a dynamic reference in my MATCH and COUNTIF function.
EX
Column F Column H
Screen1 (if Screen1 = value in my dynamic range pass me back value in a list)
Screen2 (if Screen2 etc.
Screen3
View 3 Replies
View Related
Aug 3, 2006
The problem lies in the following line
Range(Cells(1, a), Cells(b, a)).Formula = _
"=(rc[-1]-" & min & ")/(" & max & "-" & min & ") "
When it is executed i get the 1004 error ("application-defined or object-defined error)...
min and max are defined (as worksheetfunction.min and max of a selection), and their values are correct. The problem seems to lie in the max variable, namely if i simplify the formula to just
Range(Cells(1, a), Cells(b, a)).Formula = "=(rc[-1]-" & min & ")"
it works ok, but if it is
Range(Cells(1, a), Cells(b, a)).Formula = "=(rc[-1]-" & max & ")"
I get the error.
I am completely baffled considering both variables are defined in the same way i.e.
min = Application.WorksheetFunction.min(Selection)
max = Application.WorksheetFunction.max(Selection)
View 9 Replies
View Related
Oct 8, 2007
Here is what I would like to do: Have a formula like Max(B12:B14) change to Max(B12:B18) when I change the value in different cell from 3 to 7. I would like to stay away from the macro world and keep in formula world if that is possible.
View 6 Replies
View Related
Dec 3, 2013
Code:
=SUMPRODUCT(--(_NamedRng1=NamedRng2),$B$49:$F$49)
I am using the above formula in my code with two Named Ranges
Code:
Set Rng3 = Range("_NamedRng1").Offset(1, 0)
=SUMPRODUCT(--(_NamedRng1=NamedRng2),rng3)
[/CODE]
I want to set the range $B$49:$F$49 in my code and I have tried the above, but it does not work.
I want to allow for the fact my end user may insert rows so do not want to use $B$49:$F$49
View 2 Replies
View Related
Nov 10, 2006
Say you define a public range variable called Inputworksheet and you set it to refer to the worksheet called Inputworksheet. You have a separate string variable with the value Inputworksheet. How do you get this string variable value to call/control the range variable Inputworksheet?
I am getting an excel worksheet value from a lookup function that corresponds to the name of a VBA range variable. Once I have this worksheet value, I would like to use the range variable that has the same name as the worksheet value.
View 5 Replies
View Related
Apr 4, 2008
I am trying to autofill dynamic ranges that have column variables (d) and row variables (x)... I am having a hard time with the syntax on this
View 9 Replies
View Related
Mar 11, 2008
I am using a variable named " Totals" as a range type to refference the range in a formula. It works the way I have it.
Dim Totals As Range
Set Totals = [U37: AE37]
Now instead of the absolute refference, I would like to change the row refference by an offset of my current row, using a formula with a varriable. The columns stay the same.
View 3 Replies
View Related
Feb 19, 2010
I am trying to write a macro which will autofill specific columns. The macro will set the range from the start of my autofill to the end of my autofill as a constant range.
The problem I need to get around is the end of my range can always change each time I run the macro. For instance, the first time I run the macro I may only need to autofill from row 4 to row 15. The next time, I may only need to autofill from row 4 to 23 (because of user updates). How can I make the end of my range not be a constant address but variable?
View 6 Replies
View Related
Jan 27, 2012
I am trying to write code to select a range in a worksheet where the last cell in the range is variable.
Sub DataTest()
Dim LastColumn As Integer
Dim LastRow As Long
Dim LastCell As range
[Code].....
View 8 Replies
View Related
Jan 25, 2013
I have a named range, called SubjectNamesPastoral on a worksheet called Worksheets("Group to Teacher")
I can't assign the named range to the rngSubjectFamilyRangeOnSubjectUsedSheet variable in vba.
the first two lines of code work fine, the msgbox shows "E100:E105", happy days!
However when I try to assign the same range to the rngSubjectFamilyRangeOnSubjectUsedSheet variable, the debugger runs past the 'Set' line without error, but throws 'error 91' at the second msgbox.
VB:
thisString = "SubjectNames" & strSubjectFamilyOfGroup
MsgBox Range(thisString).Address
Set rngSubjectFamilyRangeOnSubjectUsedSheet = Worksheets("Group to Teacher").Range(thisString)
View 1 Replies
View Related
Jul 16, 2009
I am using the code below to copy a range and paste it over a variable range.
View 4 Replies
View Related
Mar 6, 2008
I have been working on part of the code for my spreadsheet and it works fine in the spreadsheet “Databaseform” however when I copied the code to my master spreadsheet “Paul_PartLocDBCombo” it does not work, I get the error:
Method ‘ range’ of object ‘_worksheet’ failed
The code is then highlighted in yellow, the code is:
Set rng = wksPartsData.Range("a1", Range("a65536").End(xlUp))
Meaning this part is incorrect but I don’t know why? To work it: go to Databaseform and press start. Enter 7mm in the product field and press find all. It will then return all the matching results in the userform. Its this I want to try and achieve on the other spreadsheet when the button find label is pressed.
View 3 Replies
View Related
Oct 25, 2007
I have a range "C1:Cx" where i want x to be the value from a value "overallLastRow". How do I write this?
View 9 Replies
View Related
Oct 26, 2008
This is just a simple question but I can't seem to find the answer in any of the hepl files. I want to refer to a range by using a variable but can't get the syntax right.
for example instead of
View 2 Replies
View Related
Feb 19, 2009
I am in need of code to sum the above range. But it is different range every day. My company will add the deposit amounts each day from each deposit sheet.
ie:
48000
80000
12000
3000
200
45000
10000
And so on. I have posted an example spreadsheet if needed. (The portion is green is all that needs to be summed but keep in mind it changes amount of rows included changes each day, and the yellow is where the solution goes, but I can easily change that). There are other formulas needed but I have figured those out. I need to run this macro daily just for the last group.
View 6 Replies
View Related
Mar 14, 2012
I have a problem of setting a range of row that might expand regularly.
I tried a simple method but...
Code:
' Count the used range row
Dim count As Integer
Dim usedrow As String
count = ActiveSheet.UsedRange.Rows.count
usedrow = "C" & count
' The items are in A1:A105
Set AllCells = Range("C4:usedrow")
View 2 Replies
View Related
Mar 7, 2008
I left my Excel books at home, so I can't even look up the answer, and it's incredibly frustrating, since I know it's something small that I'm missing.
I've got a code that I want to cycle thru 12 ranges, named "Retrieve1" thru "Retrieve12". This is the snippet of code that I'm having the issue with is:
For I = 1 To X
NextRange = "Retrieval" & I
Range(NextRange).Select
Application.Run Macro:="EssMenuRetrieve"
Next I
I only made the "NextRange" variable because I originally had "Retrieval" & I in the range select statement and it didn't work.
View 9 Replies
View Related
Dec 9, 2008
I am using this coding
LR = Sheets("Sheet2").Range("A" & Rows.Count).End(xlUp).Row
Range("A" & Row.counts & ":" & "D" & Rows.Count).Copy Destination:=Sheets("Sheet2").Range("A" & LR + 1)
And it keeps giving me the error "Object required"
I am trying to copy from A-D and the row is a variable to which row was checkmarked at that time.
View 9 Replies
View Related
Nov 6, 2006
I am trying to create a spreadsheet that will predict the quantity of a product sold in a given month based on the number of new clients that month and the frequency with which the existing clients will need that product to be replaced. E.g. Washing Up Liquid is required by every new client and they will need a new one each month. Toilet Cleaner is required by every new client and they will need a new one every 3 months.
I have 'hard coded' the two examples into the formula on the "Non-Variable" sheet. However the Frequency of Replacement is speculation; it may traspire that a bottle of Toilet Cleaner only lasts 2 months, in which case I would have to go into each cell and change the formula to reflect this. I believe Add or SUM Every nth Cell may hold the answer but I am failing to get it to work with my data due to being a novice and not really understanding the formulae used! The second sheet is my attempt.
As you can see, it counts 3 months forward from the first month, not 3 months BACK from the CURRENT month. It also simply doesn't work: Washing Up Liquid should equal 285. Ideally I would like to keep the format of the 1st sheet as this matches the rest of the the workbook (not included).
View 4 Replies
View Related
Dec 23, 2006
still trying to figure it out how the logic in VBA works
'this selects a block of sells and put them in variable rormu. Right?
Set test = ActiveSheet. Range("i65535").End(xlUp).Offset(-1, -3)
Set test2 = ActiveSheet.Range("i65535").End(xlUp)
Set formu = Range(test, test2)
'here i try to create another variable for a range after last used row
Set newg = ActiveSheet.Range("f65535").End(xlUp).Offset(2, 0)
Set newg2 = ActiveSheet.Range("f65535").End(xlUp).Offset(3, 3)
Set pst = Range(newg, newg2)
View 6 Replies
View Related
Mar 8, 2007
I have reached a point in my code where I have a variable range selected. I want to autofill the selected range of data to a new range.
My code is:
Range(Cells(7, LastReportColumn - 1), Cells(LastReportRow, LastReportColumn - 1)).Select
Set DestinationRange = Range(Cells(7, ReqMonths + 5), Cells(LastReportRow, ReqMonths + 5))
Selection.AutoFill Destination:=(DestinationRange), Type:=xlFillDefault
The select part works. However on the second line (set DestinationRange) I get a type missmatch.
View 5 Replies
View Related
May 1, 2007
I searched and I seached but I cant find the answer. I want to paste a set of cells in a blank range that is next to data already in the workbook. I cant get the right wording for the variables in the range I want to paste to. Here is what I got so far, the red text is what I am getting hung up on. (ya I know it sucks)
Dim mycel1 As Range
Dim mycel2 As Range
Set mycel1 = Range("A1").End(xlToRight).End(xlDown).Offset(0, 6)
Set mycel2 = Range("A2").End(xlToRight).Offset(0, 1)
Range("N2").select
Selection.Copy
Range(mycel1, mycel2).Paste
View 5 Replies
View Related
Aug 16, 2007
Dim varAAR As Variant
varAAR = Range(Selection, Selection.End(xlToRight)).Select
. Range(Selection, Selection.End(xlDown)).Select
But the way I understand it, varAAR will only equal the first line, I want it to be the range that is selected from both lines.
View 5 Replies
View Related
Oct 5, 2012
How to sum using variable start and end points?
For example,
Column A is the list of start dates, and Column B is the list of end dates to be used at the variables.
Column C is a list of dates, and Column D is the corresponding temperature data to Column C.
What I would like to do is create a new column (E) that sums the temperature data from Column D based on the start and end dates from Column A and B respectively (these dates to be used to match the dates in Column C).
View 6 Replies
View Related
Oct 24, 2012
I have a problem with a worksheet that my company accounting system exports every month.
Attached : sample of the worksheet.
In column ( F ) , I need a macro to do the following calculations:
1- Check for the Title - if it begins with "Cost Center"
2- Check for the Title - if it begins with "Account Code"
3- Detect the Range Start just below "Account Code" , and End with the row above "Total"
4- Concatenate the string written in each row of the range with the string in "Cost Center"
The Story is:
Each Month I've this worksheet with hundreds of Cost Centers and subsidiary Account Codes, And to be able to analyze the accounts efficiently I need to concatenate both Cost Centers & Account Codes manually ( as you see coloring sample in the attached file ). Which led to wasting many hours , and high risk of error while copying and pasting formulas.
View 3 Replies
View Related