FormulaR1C1 and #REF!

SBF12345

Well-known Member
Joined
Jul 26, 2014
Messages
614
I am receiving the #REF ! error in cells on a sheet generated when applying the following code into a vba sub.

When I view the formula in the sheet the #REF ! symbol is in the first R1C1 cell referenced (R[-23]C[-7]) and (R[-69]C[-7])

Code:
Range("L6").value = "dprice1"    Range("L7").FormulaR1C1 = "=((R[-23]C[-7])-(RC[-7]))/RC[-7]"
    Range("M6").value = "dprice2"
    Range("M7").FormulaR1C1 = "=((R[-69]C[-8])-(RC[-8]))/RC[-8]"

I am confused as to why the #REF ! error is being displayed. How are the #REF ! cells "invalid"?
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
And in col M your trying to up 69 rows from row 7
 
Upvote 0
Take just the first one
Range("L7").FormulaR1C1 = "=((R[-23]C[-7])-(RC[-7]))/RC[-7]"

You're putting the formula in L7.
R[-23] is 'Offsetting' from the row you put the formula (7) by -23 rows, so it's trying to go 23 rows 'above' row 7, which doesn't exist.

What are you expecting the end result formula to look like in the cell ?
 
Upvote 0
I am looking for a percentage value in the resulting cells in column "L".

Is it possible to return a value of "0" if the cells are "invalid" say for the first 16 cells in the case of the -23 and 62 in the case of the -69?

Oddly enough, every cell in column "L" is returning a #REF ! value even at row values of 2000+
 
Upvote 0
What are you expecting the end result formula to look like in the cell ?

If possible I would like to receive errors or 0 values until all cells in the formula are within a range that picks up cells with integer values. In other words at row 24 I would like to have a numerical value show in the column with the formula using the -23 value.
 
Upvote 0
What I mean is, imagine you are not using VBA.
You're entering the formulas into the cells by hand.
What would those formulas be ?
 
Upvote 0
I'm not sure I am following you here.

The formulas would find % changes in prices for differences between the current date and another date...23 and 69 days away from the current date. In A1 a formula might look like:

Code:
=(A5-A28)/A28

I am not sure how to handle the values that result from ranges that are outside the available spreadsheet given the current R1C1 structure.

I may be able to start from the bottom of the page and autofill up to the top. What do you think?
 
Upvote 0

Forum statistics

Threads
1,214,932
Messages
6,122,332
Members
449,077
Latest member
jmsotelo

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