0

I have this question based on a question asked in this link

For example, the formula in cell C1 Sheet1 is =VLOOKUP(A1,Sheet2!A:B,2,FALSE)

The code I've tried which work is only the "test-5"

Sub test()

'test-1
Range("C1").FormulaR1C1 = "=VLOOKUP(rc[-2],'" & Sheet2.Name & "'!c[1]:c[2],2,false)"
'=VLOOKUP(A1,Sheet2!D:E,2,FALSE) ---> wrong formula

'test-2
Range("C1").FormulaR1C1 = "=VLOOKUP(rc[-2],'" & Sheet2.Name & "'!A:B,2,false)"
'=VLOOKUP(A1,Sheet2!A:(B),2,FALSE) ---> wrong formula

'test-3
Range("C1").FormulaR1C1 = "=VLOOKUP(rc[-2],'" & Sheet2.Name & "'!$A:$B,2,false)"
'throw error 1004

'test-4
Range("C1").FormulaR1C1 = "=VLOOKUP(rc[-2],'" & Sheet2.Name & "'!r[1]c[1]:r[100]c[2],2,false)"
'=VLOOKUP(A1,Sheet2!D2:E101,2,FALSE) ---> wrong formula

'test-5
Range("C1").FormulaR1C1 = "=VLOOKUP(rc[-2],'" & Sheet2.Name & "'!r1c1:r100c2,2,false)"
'=VLOOKUP(A1,Sheet2!$A$1:$B$100,2,FALSE) ---> formula work but the range is with a defined row number

End Sub

So if the answer is :
it's not possible, then I'd be glad if there is an explanation about this.
it's possible, then how ?

I also curious in test4 vs test5.
If in test5, r1c1:r100c2 gives a correct range $A$1:$B$100 with $ sign
Why in test4, r[1]c[1]:r[100]c[2] don't give A1:B100 without $ sign,
but still refer the cell as if it offsetting based on cell C1 Sheet1 (D2:E101)?

Any kind of help would be greatly appreciated.
Thank you in advanced.

karma
  • 1,999
  • 1
  • 10
  • 14
  • 2
    Why use R1C1 when you could use A1 method with Range.Formula? To get R1C1 absolute refs miss out the [] so Sheet2.Name & "!C1:C2 – Charles Williams Jun 23 '22 at 08:00
  • @CharlesWilliams, I'm just curious if it use .formular1c1. Thank you for the answer. It work ! I should've known that I also must try the `c1:c2` after in test5 I try with `r1c1:r1000c2`. – karma Jun 23 '22 at 08:11

0 Answers0