mellowest
05-24-2018, 12:21 PM
Hello,
I cannot figure out how to make this work:
Sub mylookup()
Dim thevalue As String
Dim wsLookup, wsSource As Worksheet
Dim sourceLastRow, lookupLastRow As Long
Dim i As Long
'On Error Resume Next
Set wsLookup = ThisWorkbook.Worksheets("Lookup")
Set wsSource = ThisWorkbook.Worksheets("Source")
For i = 2 To 11
thevalue = Application.WorksheetFunction.VLookup(wsLookup.Cells(i, 2), wsSource.Range("B:C"), 2, False)
Debug.Print thevalue
Next
If Not IsError(thevalue) Then
thevalue = thevalue
Else
End If
End Sub
Problem: The last matched value in range "B:C" is returned as many times as the loop runs if I include on Error Resume. If I exclude it, only the matched values return and there are no repeats, but, only because I get a run-time error 1004.
I know this is super simple, but as a neophyte, any help will help.
Thanks
I cannot figure out how to make this work:
Sub mylookup()
Dim thevalue As String
Dim wsLookup, wsSource As Worksheet
Dim sourceLastRow, lookupLastRow As Long
Dim i As Long
'On Error Resume Next
Set wsLookup = ThisWorkbook.Worksheets("Lookup")
Set wsSource = ThisWorkbook.Worksheets("Source")
For i = 2 To 11
thevalue = Application.WorksheetFunction.VLookup(wsLookup.Cells(i, 2), wsSource.Range("B:C"), 2, False)
Debug.Print thevalue
Next
If Not IsError(thevalue) Then
thevalue = thevalue
Else
End If
End Sub
Problem: The last matched value in range "B:C" is returned as many times as the loop runs if I include on Error Resume. If I exclude it, only the matched values return and there are no repeats, but, only because I get a run-time error 1004.
I know this is super simple, but as a neophyte, any help will help.
Thanks