Add R1C1 Formula With Code & Variables
Sep 4, 2007
I am using follwoing vb code to enter formula to sum a range. However it is giving sum of different range.
Cells(Row, Column).FormulaR1C1 = "=SUM(R[" & a & "]C[" & b & "]:R[" & x & "]C[" & y & "])"
Where a, b , x and y are variables containg starting row, starting column, last row and last column value like a=19; b=3; x=24 and y=3. When i check the formula in that cell, it appears as Sum(F25:F30)
View 3 Replies
ADVERTISEMENT
May 19, 2007
I am trying to figure out how to use a variable as a row number for use in a range name and/or a pivot table range. Right now I have a range of R571C17, but the row number will change with each use of the pivot table formation macro.
View 3 Replies
View Related
Apr 24, 2008
Hello I'm looking for some clarification about how to use "= SUM(RC:RC)". I don't understand what the RC:RC represents. I thought that this was the directions for where to "position" the formula, but I think I'm missing something.
I was able to include the correct cells that I need summarized, but the answer is not right; it's zero.
Public Sub SubColumn(CritStr As String) ...
View 8 Replies
View Related
May 22, 2008
I would like to use a varible Cell for the following forumula:
ActiveCell.Formula = "= ROUND(PIExpDat(""TimeEq('""&Cells(RowNdxG,4)&F$2,F$3,F$4,F$5,0,)/3600,1)"
I have underlined the variable. This is not working but is rather showing up as a string value Cells(RowNdxG, 4).
View 6 Replies
View Related
Mar 24, 2007
=IF(CEILING(B9/0.5,1)>40,MAX(CEILING(B9/0.55,1),40),MAX(CEILING(B9/0.5,1),36))-0.01
Edit B9 to the R1C1 style of cell reference, how to do that?
View 3 Replies
View Related
Feb 5, 2009
Unzip Code - Works without Variables, Breaks with Variables.... This has been driving me bananas...
I have the
View 2 Replies
View Related
Nov 29, 2009
I am trying to insert a formula into a VBA Code but I get an error msg.
The formula is;
View 5 Replies
View Related
Nov 8, 2011
It's probably O so simple but: Using a variable in R1C1, here's the attempt:
-----------------------------
Dim RS_Period As Double
-----------------------------
RS_Period = Sheets("Sheet1").Range("B17") - 1
-----------------------------
Range("E2:E" & LastRow).FormulaR1C1 = "=(RC[-2]-OFFSET(RC[-2],9,0))/OFFSET(RC[-2],9,0)"
-----------------------------
I lieu of the "9" I need to use the "RS_Period" which is an offset value.
View 4 Replies
View Related
Nov 1, 2007
I want to subtract one date from another to find out the total waiting time, and repeat this action for multiple rows.
I'm trying to use an R1C1 formula within all of this.
Dim TotalTimes As Long
Dim iTime As Integer
TotalTimes = Cells(Rows.Count, 4).End(xlUp).Row
For iTime = 1 To TotalTimes
Cells.Find("Waiting Time").Offset(iTime, 0).FormulaR1C1 = [R[iTime]C[-1]-R[iTime]C[-2]]
View 9 Replies
View Related
Dec 31, 2009
I am writing a macro that populates some columns from other worksheets, and populates other columns with formulas. One of these formulas is a text string that includes a three digit number, with leading zeros if needed. The following formula works perfectly when typed directly into the cells:
=IF(AND(RC[15]<>"",RC[4]<>""),CONCATENATE(RC[14],"-",IF(RC[15]<10,"00",IF(10<RC[15]<100,"0",)),RC[15]),IF(AND(RC[14]="",RC[4]<>""),R[-1]C,""))
But this formula triggers a error message "Compile error: Expected: end of statement" when inserted in my sub. The "00" is highlited when the error message appears.
View 4 Replies
View Related
Apr 13, 2012
I receive an run-time error message 1004 "autofill method of range class failed" in the following setting, in the 2nd line.
In this instance, I want to copy 1 cell from the cell 2 columns before.
Code:
Range("M3").FormulaR1C1 = "=RC[-2]"
Range("M3").AutoFill Destination:=Range("M3"), Type:=xlFillDefault
View 6 Replies
View Related
Jun 20, 2008
When I first started using excell I was relatively good at it, however a few changes were made. The main one being for excell 2002 was the collumns were not by letter. A minor problem that I managed to get past. However the next was a function issue. Before I remembered a way to total rows with a simple function like =b3*c3, which worked for the first one. Then, from that point, I could copy that formula and paste it to all of the cells in the collum in which the forumula changed for individual cells to =b4*c4, =b5*c5, etc.
My questions are simple. Is there a way that I can do this on Excell 2002 without having to do it on a cell by cell basis, and is there a way to change collumns back to letters.
I've attached the spreadsheet in which I want to figure this out on. The goal, is to total price and quantities sold into the totals section without doing it on a cell by cell basis.
View 5 Replies
View Related
May 13, 2009
I have some buttons in different sheets in an excel file, each button has its own code, that is the reason I can not move the code related to each object to another location (sheet or module).
And I have one piece of code in Module1 (Auto_load) in order to execute automatically this routine every time file is opened. Inside "auto_load" routine I initialize some values of some check buttons,options buttons and positions of some objects in diferent sheets, but I can not pass the value of variables between Module and Sheet's code even when I declare as public variables and/or function.
I have the following structure: ...
View 11 Replies
View Related
Sep 15, 2008
I'm trying to develop a work spreadsheet template that is to be summarised every fortnight. Our fortnights here go Thurs-Thurs. So I figured I would start with a base date (thurs - Sept 4th) and then have the spreadsheet display the true fortnight ending upon loading. Ultimately this fortnight ending will be used to copy and paste the template information into a summary spreadsheet but for now I am trying to get this intial part working. It's linked to a command button and my attempt at code is below:
Private Sub CommandButton1_Click()
Dim Base As Date
Dim Now As Date
Dim Delta As Integer
Dim No_of_Fortnights!
Dim Rounded As Integer
Dim Fract!
Dim Fort_week_end As Date
(Note the following 8 lines are not the problem, they just open the main sheet. The problem is the eights lines starting with the word 'set')
Sheets("Technical Inquiry Form").Activate
Sheets("Technical Inquiry Form").Range("b3").Select
ActiveCell.FormulaR1C1 = "=TODAY()"
Sheets("Technical Inquiry Form").Range("b3").Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Sheets("Technical Inquiry Form").Activate
View 9 Replies
View Related
Jun 29, 2007
I have the following code for a user-defined function:
Function SeriesSum2(A, B, x, C, D, y, z, Num)
Summation = 0
For i = 1 To Num
Summation = Summation + (((A - B) * (((0.01 * B / (A - B)) _
^ (1 / (y - 1))) ^ i) + B - x) / ((1 + x) ^ i))
Next i
Product = 1
For i = 1 To Num
Product = Product * (1 + ((C - D) * (((0.01 * D / (C - D)) _
^ (1 / (z - 1))) ^ i) + D))
Next i
SeriesSum2 = WorksheetFunction.SumProduct(Summation, Product)
End Function
To simplify, suppose Num = 3, and the three terms of Summation are {3, 5, 9}. Call these S1, S2, S3. Further, suppose the first three terms of Product are {1, 4, 12}. Call these P1, P2, P3.
My desired result of the function is 3*1 + 5*4 + 9*12 = 131. Instead, I'm getting 3*12+5*12+9*12 = 204. That is, the function is returning S1*P3+S2*P3+S3*P3, while I want S1*P1+S2*P2+S3*P3.
Can anyone instruct me as to what I need to do to get my desired result? I'm guessing it has something to do with storing Product as an array, but I'm a very novice VB'er, so I'm not sure.
Of course, if there are any other glaring errors in my code,
View 9 Replies
View Related
May 10, 2007
I want to execute the following code once for each day (Mon to Sun)
Dim Day As String
Dim DeletedDept As String
Set StartRange = Cells(Range("Cashiers").Row + 1, Range(Day & "_Date").Column + 1)
Set EndRange = Cells(Range("Cashier_Totals").Row - 1, Range(Day & "_Date").Column + 3)
Set EntryRange = Range(StartRange, EndRange)
For Each cl In EntryRange
If cl.Value = DeletedDept Then cl.Value = ""
Next
View 3 Replies
View Related
Oct 28, 2008
This vba code will delete all the rows which have data in. At present it starts on A2 (so doesnt delete anything above A2. Which part of the code in red would I need to change for it to be A3 and which would I need to change for it to be B3.
View 5 Replies
View Related
Jul 6, 2012
I have two columns one with the variables names and the other with the values now I have to assign vales to teh variables dynamically using the macros and vba code.
View 7 Replies
View Related
Jul 17, 2012
I have some VBA that dumps various sheets data into an SQL Database.
Part of that requires me to sanitize all of the fields before they make it to the DB, (at least to prevent the code from breaking itself w/ errant ' characters.
right now my code is as follows
Code:
If InStr(aa, "'") > 0 Then
aa = Replace(aa, "'", "''")
End If
If InStr(bb, "'") > 0 Then
bb = Replace(bb, "'", "''")
[Code] ......
I was hoping to condense it to something like the following, however it is not working how I hoped / want it to. .. I had found somewhere out there that this Eval() function possibly could be used to 'reference' dynamic variables, however it does not appear to work at all anymore, and even then it may only have worked to 'read' and not 'write' to the variable. (Excel 2010, on Windows 7 64-bit).
Code:
itemsToSanitize = "aa,bb,cc,dd,ee,ff,gg,hh,ii,jj,kk,ll,mm,nn,oo,pp,qq,rr,ss,tt,uu,vv,ww,xx,yy,zz,aaa,bbb,ccc,ddd,eee,fff,ggg,hhh"
ITSArray = Split(itemsToSanitize, ",")
For Each thing In ITSArray
If InStr(Eval(thing), "'") > 0 Then
Eval(thing) = Replace(Eval(thing), "'", "''")
End If
Next thing
View 7 Replies
View Related
Aug 26, 2008
I was trying to use the VBA code to generate a data table:
Private Sub createDataTable(WS As Worksheet, initialRow As Integer, numCol As Integer, numRows As Integer)
Dim initialCell As Range 'specify the upper left cell
Dim RefCell As Range 'the reference cell on the caculator sheet
'activate source sheet
ActiveWorkbook.Sheets("Calculator").Activate
Set RefCell = ActiveSheet.Cells(2, 3)
WS.Activate
Set initialCell = ActiveSheet.Cells(initialRow, 1)
initialCell.offset(numRows, numCol).Select
Selection.Table ColumnInput:=RefCell
'the calculation should be automatic, if not, then calculate
WS.Calculate
End Sub
and it kept giving me an input celll not valid error on this line: Selection.Table ColumnInput:=RefCell the thing is, I have defined RefCell as a range object, so it should be OK rite?
View 4 Replies
View Related
Apr 15, 2008
I am trying to have the formula =( SUMIF(S2:S125,">0",S2:S125))/(COUNTIF(S2:S125,">0")) Put into cells through vba. What I did to get the formula is typed it into an excel cell to find the average of a group of cells that do contain blank cells. The formula brought out the proper results. So all I did is put the formula into vba and changed the appropriate parts. The range will not be the same of course, but there is what I have.
ActiveCell.Formula = "=(SUMIF(" & ActiveCell.Offset(orow + 2, 0).Address & ":" & ActiveCell.Offset(-1, 0).Address & ","">0""" & "," & ActiveCell.Offset(orow + 2, 0).Address & ":" & ActiveCell.Offset(-1, 0).Address & "))/(COUNTIF(" & ActiveCell.Offset(orow + 2, 0).Address & ":" & ActiveCell.Offset(-1, 0).Address & ","">0""" & "))"
When I show a msgbox for ActiveCell.Formula (Msgbox activecell.formula), it shows me the formula as above - =(SUMIF(S2:S125,">0",S2:S125))/(COUNTIF(S2:S125,">0")) Except instead of the s:ranges, it shows $L2:$L125 (which is correct). The quotes do show up around the criteria in both the sumif and countif. I keep receiving an error. I put a msgbox err.description & ", " err.number dialog in. The error comes up as ", 0" (no quotes).
View 2 Replies
View Related
May 21, 2008
I am trying to use VB to vlookup between to workbooks
1. Make active workbook WBK1
2. Make workbook being open WBK2
3. Copy and Paste between WBK1 and WBK2
4. Have a vlookup in WBK1 and bring in the values from WBK2
5. Close WKB2
6. Copy, Paste, and transpose values in wkb1 within wkb1
The script works fine until it reaches the vlookup step. I have used the vlookup by itself without the copy and paste code successfully but when I combine the two it provides me with the error 9. Subscript out of range.
View 9 Replies
View Related
Sep 29, 2011
I want to have formula with: ActiveCell:formula = I want to sum columns in a row having a column variable called: col The col variable will be the far right column and the other colunm in Row 2 will be col-3. What is the syntax to create this formula? If col = 5, formula normally would be :sum(b2:c5), I want to use col as the varialbe.
View 3 Replies
View Related
Jan 28, 2009
If a value fallw within these ranges, then the next cell should calculate the answer according to the percentages outlined.
for exmaple:
If somethng costs 250.00 then the next cell should display - 250 x .50 and the answer would be 375.00
1-500 = 50%
501-1500 = 45%
1501 - 1600 = 40%
1601 - 2500 = 35%
2501+ = 30%
and automatically calculate the answer.
I know there's an IF formula, but I can't seem to figure out how to do multiple IF's ~
View 5 Replies
View Related
Oct 24, 2013
Just got a problem with auto-populating cells with a formula that is made up of variables. My formula references the cells on another sheet, but this will be dynamic.
I'm trying to get the formula to reference e.g. cell A1 in the Calls Taken sheet, with the column held in the srtshortname variable and the row held in the formularow variable.
Code:
set rng = range(cells(introwdate, formulacol), cells(introwdate, formulacol))
rng.formula = "='Calls Taken'!" & strshortname & "" & formularow & ""
View 2 Replies
View Related
Nov 25, 2013
Writing a formula for the info below. Here is what I need basically. If B2>2, then I need it to count all central and field, STK and NSTK in column D.
location
days
stock type
Central
3
nstk
field
1
stk
[Code] ...........
View 9 Replies
View Related
Dec 3, 2007
I think I'm using the correct terminology with the term "variable", but to explain what I'm trying to do, I want to get RAND() to hold the first returned variable so I can compare it to other places RAND() has been used & if the returned value is the same as the other place, then run RAND() again.
Here is my basic formula (where $B$2 is 50):
=IF(ROUND(RAND()*$B$2, 0)+1=A4, ROUND(RAND()*$B$2, 0)+1, ROUND(RAND()*$B$2, 0)+1)
I'm trying to say in the formula above that if rand = what was already in A4 then run random again -- but this doesn't keep if from returning the same value as A4 on the second pass.
What would work is something like (where X is the assigned variable):
=IF(X=ROUND(RAND()*$B$2, 0)+1=A4, ROUND(RAND()*$B$2, 0)+1, X)
But it doesn't appear you can use X in a formula (only in a macro which I don't want to use) --
View 9 Replies
View Related
Dec 30, 2006
I have tried to reset the cell reference style back to A1 from R1C1 (Tools-->Options-->General tab-->uncheck R1C1 reference style), but when I close Excel and reopen it, the reference style changes back to R1C1 style. When I make the change I described above using the Options feature, it changes it for the current file and saves it with the file. When creating a new file in the same session, it keeps the A1 reference style, but when I close Excel and reopen it, it returns to the R1C1 style. Any ideas about how to return to the default A1 reference style for the next Excel session?
View 9 Replies
View Related
Apr 30, 2009
I get an error at the line in red, I'm sure I messed up the R1C1 Part. The first formula will be put in HZ5:HZ100 Those cells need to reference another sheet in the workbook call Varsity A3:A98. The Second formula will be IA5:IA100 Will ref Varsity B3:B98
So whenever someone enters a name in the varsity sheet the name will appear in the other sheet. This is a master workbook That will be copied many times that is why I am putting the formula in after I create the copy because the links would look at the original Varsity sheet otherwise then the user get the update links messages.
View 5 Replies
View Related
May 29, 2013
I need to know how to use a variable in an R1C1 statement. The statement is as follows:
Set rng = Sheet1.Range("A2:QFinalRowII").CurrentRegion
Ideally the statement would read something like,
Set rng = Sheet1.Range("A2:Q10").CurrentRegion
How would I use a variable name like "FinalRowII" instead of a number?
View 8 Replies
View Related