Using FormulaR1C1

djlangen

New Member
Joined
Jun 27, 2005
Messages
14
I am looping through a set of data to find two specific points. I save the row# as integer variables x and z. I then want to calculate the standard deviation of a column if values begining with row x and ending with row z. I tried using the FormulaR1C1 as:

Range("J4").Select
ActiveCell.FormulaR1C1 = "=STDEV(R[x]C[36]:R[z]C[36])"

Where I am storing the result from the calculation in cell J4.

What am I doing wrong?

Thanks
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
Exclude variables from the string literal.

Code:
"=STDEV(R[" & x & "]C[36]:R[" & z & "]C[36])"
 
Upvote 0
Providing you've set your references properly, try:

Code:
             Range("J4").FormulaR1C1 = "=STDEV(R[" & x & "]C[36]:R[" & z & "]C[36])"

When they're stuck inside the formula string the references can't be read.

Hope that helps,
 
Upvote 0
You need to concatenate. Also, if you really need x to z then do not use the brackets -- those are offsets.
Not tested but should go something like:
Code:
Range("J4").FormulaR1C1 = "=STDEV(R" & x & "C[36]:R" & z & "C[36])"

Note that you do not need to select J4. And that your formula is taking the standard deviation of the column 36 columns to the right of column J, *not* column 36.
 
Last edited:
Upvote 0
Why concatenate? That's so passe.:)
Code:
ActiveCell.FormulaR1C1 = Replace(Replace("=STDEV(R[x]C[36]:R[z]C[36])", "x", x), "z", z)
 
Upvote 0

Forum statistics

Threads
1,213,531
Messages
6,114,167
Members
448,554
Latest member
Gleisner2

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top