ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Referring to a relative cell within a function (https://www.excelbanter.com/excel-programming/410058-referring-relative-cell-within-function.html)

[email protected]

Referring to a relative cell within a function
 
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.

Mike H

Referring to a relative cell within a function
 
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

" wrote:

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.


[email protected]

Referring to a relative cell within a function
 
Thanks. RC[-4] did actually work, the problem wasn't there.

But why does Excel add ( and ) around L?

Mike H

Referring to a relative cell within a function
 
Hi,

I'm pleased that worked but I don't understand what you mean by
But why does Excel add ( and ) around L?


Mike
" wrote:

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

But why does Excel add ( and ) around L?


Dave Peterson

Referring to a relative cell within a function
 
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.

wrote:

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.


--

Dave Peterson

[email protected]

Referring to a relative cell within a function
 

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

But why does Excel add ( and ) around L?


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


All times are GMT +1. The time now is 01:53 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com