#1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 58
Default Gosub - Goto ?

I'm racking my brain; I thought there was a command called gosub that would
take you to a routine in your macro and then return to the gosub command.

for example.

sub test()
if x=5 gosub calc_routine

exit sub

: calc_routine
' do something

return
end sub

I've searched this site and MS and I'm stuck.

Thanks
  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 3,440
Default Gosub - Goto ?

You don't need the gosub (anymore);

Sub test()
test1
MsgBox "after test 1"
End Sub

Sub test1()
MsgBox "test1"
End Sub

--
Kind regards,

Niek Otten
Microsoft MVP - Excel

"El Bee" wrote in message ...
| I'm racking my brain; I thought there was a command called gosub that would
| take you to a routine in your macro and then return to the gosub command.
|
| for example.
|
| sub test()
| if x=5 gosub calc_routine
|
| exit sub
|
| : calc_routine
| ' do something
|
| return
| end sub
|
| I've searched this site and MS and I'm stuck.
|
| Thanks


  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 58
Default Gosub - Goto ?

Niek,

I removed the "gosub" and I still get an error.

here's a portion of my code:

While day_name < "XIT"
..
..
ActiveCell.Offset(rowoffset:=0, columnoffset:=-1).Activate
Tsd_title = ActiveCell.Value
color_indx = 0

setcolors

dayname
..
..
..
Wend
Exit Sub

: dayname
Select Case Day_Name
Case "MON"
Start_time_col = 2
Case "TUE"
Start_time_col = 4
..
..
..
return

: setcolors

Select Case Tsd_title
Case "Lead"
color_indx = 10
Case "Super"
color_indx = 5
Case "Tsd"
color_indx = 35
Case "BI"
color_indx = 45
Case "Night"
color_indx = 47
Case "Facilities"
color_indx = 9
Case "Prob Mgmt"
color_indx = 3
End Select

return




"Niek Otten" wrote:

You don't need the gosub (anymore);

Sub test()
test1
MsgBox "after test 1"
End Sub

Sub test1()
MsgBox "test1"
End Sub

--
Kind regards,

Niek Otten
Microsoft MVP - Excel

"El Bee" wrote in message ...
| I'm racking my brain; I thought there was a command called gosub that would
| take you to a routine in your macro and then return to the gosub command.
|
| for example.
|
| sub test()
| if x=5 gosub calc_routine
|
| exit sub
|
| : calc_routine
| ' do something
|
| return
| end sub
|
| I've searched this site and MS and I'm stuck.
|
| Thanks



  #4   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 3,440
Default Gosub - Goto ?

not

:dayname

but

Sub dayname
......
end sub

see the example I gave

--
Kind regards,

Niek Otten
Microsoft MVP - Excel

"El Bee" wrote in message ...
| Niek,
|
| I removed the "gosub" and I still get an error.
|
| here's a portion of my code:
|
| While day_name < "XIT"
| .
| .
| ActiveCell.Offset(rowoffset:=0, columnoffset:=-1).Activate
| Tsd_title = ActiveCell.Value
| color_indx = 0
|
| setcolors
|
| dayname
| .
| .
| .
| Wend
| Exit Sub
|
| : dayname
| Select Case Day_Name
| Case "MON"
| Start_time_col = 2
| Case "TUE"
| Start_time_col = 4
| .
| .
| .
| return
|
| : setcolors
|
| Select Case Tsd_title
| Case "Lead"
| color_indx = 10
| Case "Super"
| color_indx = 5
| Case "Tsd"
| color_indx = 35
| Case "BI"
| color_indx = 45
| Case "Night"
| color_indx = 47
| Case "Facilities"
| color_indx = 9
| Case "Prob Mgmt"
| color_indx = 3
| End Select
|
| return
|
|
|
|
| "Niek Otten" wrote:
|
| You don't need the gosub (anymore);
|
| Sub test()
| test1
| MsgBox "after test 1"
| End Sub
|
| Sub test1()
| MsgBox "test1"
| End Sub
|
| --
| Kind regards,
|
| Niek Otten
| Microsoft MVP - Excel
|
| "El Bee" wrote in message ...
| | I'm racking my brain; I thought there was a command called gosub that would
| | take you to a routine in your macro and then return to the gosub command.
| |
| | for example.
| |
| | sub test()
| | if x=5 gosub calc_routine
| |
| | exit sub
| |
| | : calc_routine
| | ' do something
| |
| | return
| | end sub
| |
| | I've searched this site and MS and I'm stuck.
| |
| | Thanks
|
|
|


  #5   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 58
Default Gosub - Goto ?

Niek,

That worked but now I'm having issues with some of my variables.

How do I declare variables so they can be used between subs or functions.

Sorry, my online help isn't working.

El Bee

"Niek Otten" wrote:

not

:dayname

but

Sub dayname
......
end sub

see the example I gave

--
Kind regards,

Niek Otten
Microsoft MVP - Excel

"El Bee" wrote in message ...
| Niek,
|
| I removed the "gosub" and I still get an error.
|
| here's a portion of my code:
|
| While day_name < "XIT"
| .
| .
| ActiveCell.Offset(rowoffset:=0, columnoffset:=-1).Activate
| Tsd_title = ActiveCell.Value
| color_indx = 0
|
| setcolors
|
| dayname
| .
| .
| .
| Wend
| Exit Sub
|
| : dayname
| Select Case Day_Name
| Case "MON"
| Start_time_col = 2
| Case "TUE"
| Start_time_col = 4
| .
| .
| .
| return
|
| : setcolors
|
| Select Case Tsd_title
| Case "Lead"
| color_indx = 10
| Case "Super"
| color_indx = 5
| Case "Tsd"
| color_indx = 35
| Case "BI"
| color_indx = 45
| Case "Night"
| color_indx = 47
| Case "Facilities"
| color_indx = 9
| Case "Prob Mgmt"
| color_indx = 3
| End Select
|
| return
|
|
|
|
| "Niek Otten" wrote:
|
| You don't need the gosub (anymore);
|
| Sub test()
| test1
| MsgBox "after test 1"
| End Sub
|
| Sub test1()
| MsgBox "test1"
| End Sub
|
| --
| Kind regards,
|
| Niek Otten
| Microsoft MVP - Excel
|
| "El Bee" wrote in message ...
| | I'm racking my brain; I thought there was a command called gosub that would
| | take you to a routine in your macro and then return to the gosub command.
| |
| | for example.
| |
| | sub test()
| | if x=5 gosub calc_routine
| |
| | exit sub
| |
| | : calc_routine
| | ' do something
| |
| | return
| | end sub
| |
| | I've searched this site and MS and I'm stuck.
| |
| | Thanks
|
|
|





  #6   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 3,440
Default Gosub - Goto ?

If you need to; declare them outside your Subs, in the top of the Module.

Many pros wouldn't consider that good coding practice, though.
If your application isn't too complex; don't bother. Otherwise, consider supplying arguments to subs rather than relying on global
variables.

--
Kind regards,

Niek Otten
Microsoft MVP - Excel

"El Bee" wrote in message ...
| Niek,
|
| That worked but now I'm having issues with some of my variables.
|
| How do I declare variables so they can be used between subs or functions.
|
| Sorry, my online help isn't working.
|
| El Bee
|
| "Niek Otten" wrote:
|
| not
|
| :dayname
|
| but
|
| Sub dayname
| ......
| end sub
|
| see the example I gave
|
| --
| Kind regards,
|
| Niek Otten
| Microsoft MVP - Excel
|
| "El Bee" wrote in message ...
| | Niek,
| |
| | I removed the "gosub" and I still get an error.
| |
| | here's a portion of my code:
| |
| | While day_name < "XIT"
| | .
| | .
| | ActiveCell.Offset(rowoffset:=0, columnoffset:=-1).Activate
| | Tsd_title = ActiveCell.Value
| | color_indx = 0
| |
| | setcolors
| |
| | dayname
| | .
| | .
| | .
| | Wend
| | Exit Sub
| |
| | : dayname
| | Select Case Day_Name
| | Case "MON"
| | Start_time_col = 2
| | Case "TUE"
| | Start_time_col = 4
| | .
| | .
| | .
| | return
| |
| | : setcolors
| |
| | Select Case Tsd_title
| | Case "Lead"
| | color_indx = 10
| | Case "Super"
| | color_indx = 5
| | Case "Tsd"
| | color_indx = 35
| | Case "BI"
| | color_indx = 45
| | Case "Night"
| | color_indx = 47
| | Case "Facilities"
| | color_indx = 9
| | Case "Prob Mgmt"
| | color_indx = 3
| | End Select
| |
| | return
| |
| |
| |
| |
| | "Niek Otten" wrote:
| |
| | You don't need the gosub (anymore);
| |
| | Sub test()
| | test1
| | MsgBox "after test 1"
| | End Sub
| |
| | Sub test1()
| | MsgBox "test1"
| | End Sub
| |
| | --
| | Kind regards,
| |
| | Niek Otten
| | Microsoft MVP - Excel
| |
| | "El Bee" wrote in message ...
| | | I'm racking my brain; I thought there was a command called gosub that would
| | | take you to a routine in your macro and then return to the gosub command.
| | |
| | | for example.
| | |
| | | sub test()
| | | if x=5 gosub calc_routine
| | |
| | | exit sub
| | |
| | | : calc_routine
| | | ' do something
| | |
| | | return
| | | end sub
| | |
| | | I've searched this site and MS and I'm stuck.
| | |
| | | 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
goto (F5) question dford Excel Discussion (Misc queries) 2 January 13th 07 04:54 AM
GOTO with Macros PBallia Excel Discussion (Misc queries) 1 September 18th 06 12:37 AM
Goto code Bob Excel Discussion (Misc queries) 4 July 6th 06 05:44 PM
Excel GOTO joeski Excel Discussion (Misc queries) 3 May 10th 06 12:06 PM
If.....Then GoTo....... Alec H Excel Discussion (Misc queries) 4 February 22nd 06 02:42 PM


All times are GMT +1. The time now is 11:42 PM.

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"