brewitbold
New Member
- Joined
- Oct 13, 2016
- Messages
- 5
Hello!
This is my first time using an On Error GoTo solution within a macro and I cannot find any documentation online to help me with an issue I am running in to. I think it's an issue of where in the loop I have placed the error handling line.
The snippet of code below performs a lookup and stores either a 1 or a 2 in a variable called "State." If the lookup value does not exist on the second sheet, then then "State" should be "Not Found. Currently what is happening is that a record that is NOT on the second sheet initially returns "Not Found" (yay!) and then the code loops back up to the if statement and overwrites the result to "2."
My thought was that the error handling would simply produce "not found" and then move to the next row.
I have commented out the actual vlookup, as it is long and does not seem to be impacting the actual error (I've tested it and it returnes accurate values 100%)
Thank you for the assistance and collective brain power that this site attracts!
This is my first time using an On Error GoTo solution within a macro and I cannot find any documentation online to help me with an issue I am running in to. I think it's an issue of where in the loop I have placed the error handling line.
The snippet of code below performs a lookup and stores either a 1 or a 2 in a variable called "State." If the lookup value does not exist on the second sheet, then then "State" should be "Not Found. Currently what is happening is that a record that is NOT on the second sheet initially returns "Not Found" (yay!) and then the code loops back up to the if statement and overwrites the result to "2."
My thought was that the error handling would simply produce "not found" and then move to the next row.
I have commented out the actual vlookup, as it is long and does not seem to be impacting the actual error (I've tested it and it returnes accurate values 100%)
Code:
For i = 2 To lastRow
lookupValue= 'Returns the value of a Vlookup from another sheet.
On Error GoTo EmpNotFound:
If lookupValue= "string1" Then
state = "1"
Else
state = "2"
End If
Next
EmpNotFound:
state = "Not Found"
Resume Next
Thank you for the assistance and collective brain power that this site attracts!