PDA

View Full Version : [SOLVED:] VLOOKUP Error : Need a VBA to copy matching row cell data in sheet1 from sheet2



ucan
03-03-2022, 05:31 PM
Hi,

I need help on an error related to VLOOKUP.
My cell data is in column E and Reference cell data are in
I am using the Excel formula: =VLOOKUP(E2, K$2:Z$34555, 2, 0)

Please help with a VBA code for the same if I keep my data in Sheet1 and reference cell data upto any cell or row in "Reference sheet".


Thanks in advance.

anish.ms
03-04-2022, 06:49 PM
'Example


Sub MylVlookup()
Dim myLookupValue As String
Dim myVLookupResult As String
Dim myTableArray As Range


With ThisWorkbook
myLookupValue = .Sheets("Sheet1").Range("A2").Value
Set myTableArray = .Sheets("Reference sheet").UsedRange
End With


myVLookupResult = WorksheetFunction.VLookup(myLookupValue, myTableArray, 2, False)


End Sub

ucan
03-08-2022, 07:51 AM
Thank you. Worked perfectly.