Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
Cue Cue is offline
external usenet poster
 
Posts: 47
Default Skip a statment or line in vba

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   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 8,856
Default Skip a statment or line in vba

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   Report Post  
Posted to microsoft.public.excel.misc
Cue Cue is offline
external usenet poster
 
Posts: 47
Default Skip a statment or line in vba

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   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 8,856
Default 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 -


  #5   Report Post  
Posted to microsoft.public.excel.misc
Cue Cue is offline
external usenet poster
 
Posts: 47
Default Skip a statment or line in vba

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   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 8,856
Default Skip a statment or line in vba

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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with If statment pm Excel Discussion (Misc queries) 3 January 29th 08 04:09 PM
If statment Jason Excel Discussion (Misc queries) 3 January 3rd 08 11:39 PM
if statment Dreamstar_1961 Excel Worksheet Functions 5 April 17th 07 01:30 PM
If statment if its possible. atb Excel Discussion (Misc queries) 2 October 17th 06 05:50 PM
How, on a line chart, to skip blank entry rather than plot as 0? JohnTerp Charts and Charting in Excel 1 July 12th 06 11:11 PM


All times are GMT +1. The time now is 07:46 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"