flyingmonkeyofdoom
Board Regular
- Joined
- Sep 22, 2010
- Messages
- 161
The below code is ment to look down the raw data and then use a vba vlookup to find the corrisponding item in a lookup table and bring back the result.
Within the raw data are items that will not be in the lookup table and i was hoping the the "on Error" would catch these; but it seems to work only once then i get the 1004 error box message appear (which this was meant to stop).
would anyone be able to advise me where i've went wrong in my code and how i can fix it?
Within the raw data are items that will not be in the lookup table and i was hoping the the "on Error" would catch these; but it seems to work only once then i get the 1004 error box message appear (which this was meant to stop).
would anyone be able to advise me where i've went wrong in my code and how i can fix it?
Code:
Sub AddWaiting()Dim iLastrow As Long, i As Long
On Error GoTo MyErrorHandler:
'Find last row
RawData.Activate
With RawData
iLastrow = .Cells(.Rows.Count, 1).End(xlUp).Row
End With
'Loop for vlook up
For i = 2 To iLastrow
If RawData.Range("j" & i) = "" Then
RawData.Range("o" & i) = ""
Else
RawData.Range("o" & i) = Application.WorksheetFunction.VLookup(RawData.Range("j" & i), Weighting.Range("A:B"), 2, True)
End If
Debug.Print i
MyErrorHandler:
If Err.Number = 1004 Then
Range("o" & i) = "No Code"
End If
Next i
End Sub