Referring to a relative cell within a function

P

p.numminen

Cells(ActiveCell.Row + 0, 6).FormulaR1C1 = "=VLOOKUP(RC[-4];'Sheet2'!
A:D;3;FALSE)" doesn't work. How do you relatively refer to a cell
within a function? RC[-4] should be replaced.
 
M

Mike H

Hi,

I'm not sure I fully understand what you mean but maybe this

Cells(ActiveCell.Row + 0, 6).FormulaR1C1 =
"=VLOOKUP(RC[-4],Sheet2!R[-15]C[-6]:R[14]C[-3],3,FALSE)"

Note that I've used , instead of ; for my version of Excel so change these
back.

Mike
 
P

p.numminen

Thanks. RC[-4] did actually work, the problem wasn't there.

But why does Excel add ( and ) around L?
 
D

Dave Peterson

Cells(ActiveCell.Row, 6).FormulaR1C1 = "=VLOOKUP(RC[-4],'Sheet2'!C1:C4,3,FALSE)

VBA is USA centric--use commas, not semicolons.

And 'Sheet2'!A:D wasn't in R1C1 reference style.

Cells(ActiveCell.Row + 0, 6).FormulaR1C1 = "=VLOOKUP(RC[-4];'Sheet2'!
A:D;3;FALSE)" doesn't work. How do you relatively refer to a cell
within a function? RC[-4] should be replaced.
 
P

p.numminen

I'm pleased that worked but I don't understand what you mean by

When I go to the cell that the macro affected, the function bar shows
parentheses around the L, which indicates column.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top