I tried looking through the other answers, but nothing really seemed to help me out. As the title states, I'm getting a "Block if without end if" error. I'm trying to put in a conditional statement that ends the sub if its met. To be more specific, I'm formatting data that can only be formatted one job at a time. I want to automatically end the sub if it determines there are multiple jobs in the spreadsheet. Here's what I've got so far.
Sub SUBNAMEHERE
(Lots of other code)
JobNo = (code that figures out how many jobs there are)
If JobNo > 1 Then
MsgBox (warning message)
End Sub
End If
(The rest of the code)
If anyone could help me out, it would be much appreciated.
Try Exit Sub
rather than End Sub
.
When you say End Sub
, you're telling VB that you're done defining the routine. So if you haven't ended the If
before that, it'll be considered incomplete.
Course, even if you did end the If
before that, you'd almost certainly wind up getting errors about code outside of a function. (I don't know VBA all that well..but that's how most flavors of VB work.)
Sub SUBNAMEHERE
(Lots of other code)
JobNo = (code that figures out how many jobs there are)
If JobNo > 1 Then
MsgBox (warning message)
-------> End Sub <------
End If
(The rest of the code)
The End Sub should go on the bottom of the Sub
And as your the commentors pointed out, it's Exit Sub
that you're looking for.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With