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

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.

Oaktree

MrExcel MVP
Joined
Jun 20, 2002
Messages
8,108
Office Version
  1. 365
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

Richard Schollar

MrExcel MVP
Joined
Apr 19, 2005
Messages
23,707
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,191,170
Messages
5,985,063
Members
439,938
Latest member
MAlhash

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