VBA Vlook Up formula using R1C1

miltonjeff

New Member
Joined
Aug 14, 2017
Messages
2
I have started just recently into VBA. I am working on a vlookup formula. Thought I could simplify it using an R1C1 formula but it won't work for me.

I am looking up one one sheet and referencing another sheet. I have about 50 rows of data list.

Here is the VBA code that is working for me:

Sub vsrch()


Dim ws1 As Worksheet, ws2 As Worksheet
Dim srchres As Variant

Set ws1 = Worksheets("Sheet1")
Set ws2 = Worksheets("Staff Listing")

srchres = Application.WorksheetFunction.VLookup(ws1.Range("a2"), ws2.Range("A2:C100"), 2, False)
ws1.Range("d2").Value = srchres
srchres = Application.WorksheetFunction.VLookup(ws1.Range("a2"), ws2.Range("A2:C100"), 3, False)
ws1.Range("e2").Value = srchres
srchres = Application.WorksheetFunction.VLookup(ws1.Range("a3"), ws2.Range("A2:C100"), 2, False)
ws1.Range("d3").Value = srchres
srchres = Application.WorksheetFunction.VLookup(ws1.Range("a3"), ws2.Range("A2:C100"), 3, False)
ws1.Range("e3").Value = srchres

End Sub


Here is the VBA with the R1C1 that is not working for me (Once i figure out the issue then I would add the next column of data.

Sub VlookupVBA()
Dim lLastRow As Long

With Sheets("Sheet1")
lLastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
With .Range("d1:d" & lLastRow)
.FormulaR1C1 = "=VLOOKUP(RC[-1],'Staff Listing'!a2:c100,2,FALSE)"
.Value = .Value
End With
End With

End Sub

Any help would be greatly appreciated.
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
lLastRow = .Range("A" & .rows.count).end(xlup).row

.FormulaR1C1 = "=VLOOKUP(RC[-1],'Staff Listing'!a2:c100,2,FALSE)" <- A2 and C100 needs to convert to R1C1, so R2C1 and R100C3
 
Upvote 0
lLastRow = .Range("A" & .rows.count).end(xlup).row

.FormulaR1C1 = "=VLOOKUP(RC[-1],'Staff Listing'!a2:c100,2,FALSE)" <- A2 and C100 needs to convert to R1C1, so R2C1 and R100C3


Thanks, for the fix, just had to change to

=VLOOKUP(RC1,

and it worked like a charm!

Thanks!
 
Upvote 0

Forum statistics

Threads
1,214,598
Messages
6,120,441
Members
448,966
Latest member
DannyC96

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