Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
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 |
#2
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
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 |
#3
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
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 |
#4
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
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 - |
#5
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
Thank you very much Pete for the GoTo advice!
Cue "Pete_UK" wrote: 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 - |
#6
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
Spaghetti Programmers Rule OK!
Thanks for feeding back. Pete On Jun 28, 2:35*pm, Cue wrote: Thank you very much Pete for the GoTo advice! Cue |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Help with If statment | Excel Discussion (Misc queries) | |||
If statment | Excel Discussion (Misc queries) | |||
if statment | Excel Worksheet Functions | |||
If statment if its possible. | Excel Discussion (Misc queries) | |||
How, on a line chart, to skip blank entry rather than plot as 0? | Charts and Charting in Excel |