formulaR1C1 to reference specific range?

mfisher316

New Member
Joined
Mar 8, 2007
Messages
7
I have a counter loop macro written that cuts/pastes columns, and inserts rows if specific conditions apply. Here's the dilemma, say column C is my active cell. I need a vlookup formula that looks at column A, next row, against data in the range A4:B55 on a separate worksheet. I have tried the following but none have worked:

activecell.formulaR1C1= "=vlookup(+R[1]C[-2],Costcodes!$A$4:$B$55,2)" - can you not have specific range reference w/ an r1c1 formula??

I have set variables x and y to be eqal to "4 - counter" and "55-counter" respectively (so that it always pulls from the correct range) with the following formula:
activecell.formulaR1C1="=vlookup(+R[1]C[-2],Costcodes!R[x]C[-2]:R[y]C[-2],2)"
but that hasn't worked either. Any suggestions?

Thanks in advance!
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
If x and y are variables, they shouldn't be inside the quotes. Try:

Code:
activecell.formulaR1C1="=vlookup(+R[1]C[-2],Costcodes!R[" & x & "]C[-2]:R[" & y & "]C[-1],2)"
 
Upvote 0
Hi

As you are accessing the FormulaR1C1 property of the cell, you shouldn't attempt to use A1-style references in the formula string.

Within R1C1 style referencing, the [] brackets denote a relative reference - since I assume the range on Costcodes sheet is fixed, you need to drop these references. Also, you need to concatenate the variable values with the formula string for Excel to recognise the variables as variables, and not simply part of the string. Hence:

Code:
activecell.formulaR1C1="=vlookup(R[1]C[-2],Costcodes!R" & x & "C1:R" & y & "C2,2)"
 
Upvote 0

Forum statistics

Threads
1,214,632
Messages
6,120,652
Members
448,975
Latest member
sweeberry

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