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
 

Some videos you may like

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.

iliace

Well-known Member
Joined
Jan 15, 2008
Messages
3,543
Office Version
  1. 365
  2. 2016
  3. 2010
Platform
  1. Windows
Exclude variables from the string literal.

Code:
"=STDEV(R[" & x & "]C[36]:R[" & z & "]C[36])"
 

Smitty

Legend
Joined
May 15, 2003
Messages
29,536
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,
 

Greg Truby

MrExcel MVP
Joined
Jun 19, 2002
Messages
10,014
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:

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,232
Office Version
  1. 365
Platform
  1. Windows
Why concatenate? That's so passe.:)
Code:
ActiveCell.FormulaR1C1 = Replace(Replace("=STDEV(R[x]C[36]:R[z]C[36])", "x", x), "z", z)
 

Watch MrExcel Video

Forum statistics

Threads
1,123,402
Messages
5,601,475
Members
414,452
Latest member
Dannysamworth

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
Top