How to populate cells using VBA Vlookup
I'm trying to populate a worksheet cells with some fields from another
worksheet on the same workbook using VBA Vlookup and I'm stuck.
Worksheet users have the following data, the A1 is the Login and B1,
Number, is empty but the goal are to populate with the data from other
worksheet
Login Number
ffff
bbbb
cccc
dddd
eeee
aaaa
In the worksheet Data I've the following
Login Number
aaaa 1234
bbbb 1235
cccc 1236
dddd 1237
eeee 1238
ffff 1239
Currently I'm using this code
Sub VL()
Dim Login As Range
Set Login = Sheets("Users").Cells(2, 1)
Do Until Len(Login) = 0 'This will loop until the first empty cell
Login.Offset(0, 1).FormulaR1C1 =
Application.WorksheetFunction.VLookup(Sheets("Users").Range("$A:$A"),
[Table], 2, False)
Calculate
Login.Offset(0, 1).Value = Login.Offset(0, 1).Value
Set Login = Login.Offset(1, 0)
Loop
End Sub
and the result isn't the expected,
Login Name
ffff #N/A
bbbb
cccc
dddd
eeee
aaaa
I've search on the forum but don't find nothing to help me solving this.
thanks in advance
best regards
carlos
No comments:
Post a Comment