#1   Report Post  
Jeff
 
Posts: n/a
Default Question on VBA

Hi,

This is a partial copy of my VBA macro. My question is: Is possible in VBA
to execute a sub in an " If ... then statement?"

If TopCell Is Nothing Then
MsgBox myStr(iCtr) & " wasn't found"
Exit Sub --- here can I request the execution of sub instead of
Exit sub?
Else
.Range(TopCell, BotCell).Select
End If
Next iCtr
End With
Thanks,

  #2   Report Post  
Frank Kabel
 
Posts: n/a
Default

Hi
you can call another sub. Just insert it instead of exit sub

--
Regards
Frank Kabel
Frankfurt, Germany

"Jeff" schrieb im Newsbeitrag
...
Hi,

This is a partial copy of my VBA macro. My question is: Is possible

in VBA
to execute a sub in an " If ... then statement?"

If TopCell Is Nothing Then
MsgBox myStr(iCtr) & " wasn't found"
Exit Sub --- here can I request the execution of sub

instead of
Exit sub?
Else
.Range(TopCell, BotCell).Select
End If
Next iCtr
End With
Thanks,


  #3   Report Post  
JE McGimpsey
 
Posts: n/a
Default

One way:

With something
For iCtr = 1 to n
If TopCell Is Nothing Then
MsgBox myStr(iCtr) & " wasn't found"
MySub
Else
.Range(TopCell, BotCell).Select
End If
Next iCtr
End With
'...
End Sub


Public Sub MySub()
'Do something here
End Sub


In article ,
"Jeff" wrote:

Hi,

This is a partial copy of my VBA macro. My question is: Is possible in VBA
to execute a sub in an " If ... then statement?"

If TopCell Is Nothing Then
MsgBox myStr(iCtr) & " wasn't found"
Exit Sub --- here can I request the execution of sub instead of
Exit sub?
Else
.Range(TopCell, BotCell).Select
End If
Next iCtr
End With
Thanks,

  #4   Report Post  
Bob Phillips
 
Posts: n/a
Default

Why didn't you just try it, you would have found out very easily.

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Jeff" wrote in message
...
Hi,

This is a partial copy of my VBA macro. My question is: Is possible in VBA
to execute a sub in an " If ... then statement?"

If TopCell Is Nothing Then
MsgBox myStr(iCtr) & " wasn't found"
Exit Sub --- here can I request the execution of sub instead

of
Exit sub?
Else
.Range(TopCell, BotCell).Select
End If
Next iCtr
End With
Thanks,



  #5   Report Post  
George Nicholson
 
Posts: n/a
Default

Yes, simply call the sub.

Keep in mind that once the newly called sub finishes executing, code
execution *returns* to the current sub, on the line following where it was
called.

You only provided partial code but it seems you are within a loop.

If you call NewSub IN PLACE of your ExitSub, the loop will continue after
NewSub finishes.

If you call NewSub BEFORE your ExitSub, then ExitSub will be executed as
soon as NewSub sub finishes, so you will exit the loop (and the whole sub).

HTH,
--
George Nicholson

Remove 'Junk' from return address.


"Jeff" wrote in message
...
Hi,

This is a partial copy of my VBA macro. My question is: Is possible in VBA
to execute a sub in an " If ... then statement?"

If TopCell Is Nothing Then
MsgBox myStr(iCtr) & " wasn't found"
Exit Sub --- here can I request the execution of sub instead of
Exit sub?
Else
.Range(TopCell, BotCell).Select
End If
Next iCtr
End With
Thanks,



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
VLOOKUP question KG Excel Discussion (Misc queries) 9 May 21st 05 07:12 PM
basic pie chart question KayR Charts and Charting in Excel 4 January 23rd 05 08:16 PM
Barchart 'GroupBy' Question [email protected] Charts and Charting in Excel 1 December 16th 04 10:47 PM
Jon Peltier - Pivot Table Result for yesterday's "Complex Chart" Question Barb Reinhardt Charts and Charting in Excel 3 December 8th 04 01:48 AM
Paste Special Question Kevin Excel Discussion (Misc queries) 3 November 30th 04 11:34 PM


All times are GMT +1. The time now is 04:48 PM.

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

About Us

"It's about Microsoft Excel"