ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Worksheet Functions (https://www.excelbanter.com/excel-worksheet-functions/)
-   -   Gosub - Goto ? (https://www.excelbanter.com/excel-worksheet-functions/130561-gosub-goto.html)

El Bee

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

Niek Otten

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



El Bee

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




Niek Otten

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
|
|
|



El Bee

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
|
|
|




Niek Otten

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
| |
| |
| |
|
|
|




All times are GMT +1. The time now is 09:57 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com