youcanreachtrevor
New Member
- Joined
- May 17, 2018
- Messages
- 5
I had an if condition written and it worked just fine, but I want to add to it a condition that will allow the code to stop a couple lines before the end of the code, but the else if won't work. I keep getting an error saying "Compile error: expected: Do or For or Sub or Function or Property"
I'm just getting back into writting VBA, so I'm a bit rusty, but I couldn't find this in any other threads. I'm sure the question is a simple one. Not sure what I'm missing. ANy insight would be helpful thanks.
I'm just getting back into writting VBA, so I'm a bit rusty, but I couldn't find this in any other threads. I'm sure the question is a simple one. Not sure what I'm missing. ANy insight would be helpful thanks.
Code:
Public Sub NextItem()
Gap = 1
For p = ActiveRow To LastRow - 1
If Len(WorksheetFunction.Trim(WorksheetFunction.Clean(NISSCADSH.Cells(ActiveRow + Gap, 4).Value))) <> 0 Then
FutureRow = ActiveRow + Gap
Exit Sub
Else if (p = (LastRow - 2)) then exit
Else: Gap = Gap + 1
End If
Next
End Sub
Last edited by a moderator: