steveh8204
Board Regular
- Joined
- Aug 20, 2018
- Messages
- 151
Right, once again I'm struggling with the Next without For error. I've got a loop ("i") which if a certain condition is met (d2 > d) I want to terminate immediately and return to the beginning of the If statement.
If d2 isn't greater than I want the loop to continue until the Next command further down but I keep getting error command.
Am I missing something obvious as this isn't the first time I've had problems with this loop.
If d2 isn't greater than I want the loop to continue until the Next command further down but I keep getting error command.
Am I missing something obvious as this isn't the first time I've had problems with this loop.
Code:
r = Cells(Rows.Count, 1).End(xlUp).Row - 2
For i = 3 To r + 2
' determine the cell to get lookup value from
v = Cells(i, 1).Value
Ptrue = Application.WorksheetFunction.VLookup(v, Sheets("SAP").Range("sapstock"), 4, False)
sapstock = Cells(i, 4)
lookup1 = 0 ' make sure variable is reset from previous loops
lookup1 = Application.VLookup(v, Range("allstock"), 4, False)
d = Now
d2 = Cells(i, 5) ' if the date is in the future I need the loop to go back to the beginning.
If d2 > d Then
Next
ElseIf lookup1 = sapstock Then
Cells(i, 6).Value = "Quantity Is Correct"
Cells(i, 7).Value = "" ' used to blank cells if re-running check
Cells(i, 8).Value = ""
Else
Cells(i, 6).Value = "Incorrect Quantity"
Cells(i, 7).Value = lookup1 - sapstock
End If
Next i