Hi Guys,
I am here to ask help on creating a macro to make my life easier.
I have 2 sheets, Database and Input. In Database I have 2 columns: "Users" and "Country", I need to have the macro to autofill the column A in the Input sheet when I write the User in the column B.
The Database is updated daily so I can remove or add entries, this is why I need to have a command that keeps executing the vlookup in the column A UNTIL the end cell of column B.
edited:
this seems to work if anyone is looking for the same:
Sub Hello()
Dim ws As Worksheet
Dim LastRow As Long
Dim TargetRange As Range
On Error GoTo MyErrorHandler:
Set ws = Sheets("Database")
LastRow = ws.Cells(Rows.Count, "B").End(xlUp).Row
Set xWs = Sheets("Input")
LastRowXX = xWs.Cells(Rows.Count, "B").End(xlUp).Row
Set TargetRange = ws.Range("A1:B" & LastRowXX)
result = Application.WorksheetFunction.VLookup(Sheets("Input").Range("B1:B" & LastRow), TargetRange, 2, False)
'MsgBox result
Range("A1:A" & LastRowXX) = result
MyErrorHandler:
If Err.Number = 1004 Then
MsgBox "error"
End If
End Sub
Bookmarks