Having Trouble with this code.
I'm looking up Column A on Sheet3 on Sheet1. When it finds a match on sheet1 its supposed to take column 23 and put the results in column 13 on Sheet3. Right now its just matching Column A with Column 5 on Sheet3 and putting that value in column 13.
I'm looking up Column A on Sheet3 on Sheet1. When it finds a match on sheet1 its supposed to take column 23 and put the results in column 13 on Sheet3. Right now its just matching Column A with Column 5 on Sheet3 and putting that value in column 13.
Code:
Sub vlookup()
Dim lastrow, lastrow2, i As Long
Dim Searchfor, j, inarr As Variant
Set ws1 = ThisWorkbook.Sheets("Sheet3")
Set ws2 = Workbooks("Data").Sheets("Sheet1")
With ws2
lastrow = .Cells(Rows.Count, "E").End(xlUp).Row
inarr = Range(.Cells(5, 5), .Cells(lastrow, 23))
End With
With ws1
lastrow2 = .Cells(Rows.Count, "A").End(xlUp).Row
searcharr = Range(.Cells(2, 1), .Cells(lastrow2, 1))
outarr = Range(.Cells(2, 1), .Cells(lastrow2, 13))
End With
On Error Resume Next
For i = 1 To lastrow2
For j = 5 To lastrow
Searchfor = searcharr(i, 1)
If inarr(j, 1) = Searchfor Then
For kk = 1 To 13
outarr(i, kk - 1) = inarr(j, kk)
Next kk
Exit For
End If
Next j
Next i
With ws1
Range(.Cells(10, 13), .Cells(lastrow2, 13)) = outarr
End With
End Sub
Last edited by a moderator: