Skip a statment or line in vba
There are several ways of doing it - here's one way:
Answer = MsgBox("Do you want to delete this cell?", _
vbYesNo)
If Answer = vbYes Then
Range("A2").Select
Else
Answer = MsgBox("Do you want to close '" & _
ActiveWorkbook.Name & "'?", vbYesNo)
If Answer = vbYes Then
ActiveWindow.Close
Else
Exit Sub
Endif
Endif
'rest of code, with A2 selected
If you want to use GoTo then set up a label and jump to that (look in
VBA Help).
Hope this helps.
Pete
On Jun 28, 12:11*am, Cue wrote:
Hi Pete_UK. Thanks for your response.
I'm not sure if that would work. I should be more detailed.
I want to skip several lines in a macro/vba. Using the answer msg box, if
the answer is no then I want it to go to several lines down in the vba to
perform more actions on the workseet. if it that is possible, here is part of
the code:
* * Answer = MsgBox("Do you want to delete this cell?", vbYesNo)
* * If Answer = vbYes Then Range("A2").Select
* * If Answer = vbNo Then GoTo LN 118
It would skip to this line in vba:
* * Answer = MsgBox("Do you want to close '" & ActiveWorkbook.Name & "'?",
vbYesNo)
* * If Answer = vbYes Then ActiveWindow.Close
* * If Answer = vbNo Then Exit Sub
Is this possible? If so, how?
--
Cue
"Pete_UK" wrote:
You would use:
If * *condition * * Then
* * *action_if_true
Else
* * * action_if_false
Endif
rest_of_macro
Hope this helps.
Pete
On Jun 27, 11:35 pm, Cue wrote:
Is it possible to skip a statement(s)/line(s) in vba?
Im using answer msg box and I want to skip or pass a section if the answer
is no.
--
Cue- Hide quoted text -
- Show quoted text -
|