ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Toggle Code Calls (https://www.excelbanter.com/excel-programming/354669-toggle-code-calls.html)

Desert Piranha[_56_]

Toggle Code Calls
 

Hi all,

If these work, to call macro's:

Sub RunCode1()
Code1
End Sub

Sub RunCode2()
Code2
End Sub

Why dosen't this work, to toggle the calls?
Sub testoftoggle()
If Code1 = True Then
Code2
Else
Code1
End If
End Sub


--
Desert Piranha


------------------------------------------------------------------------
Desert Piranha's Profile: http://www.excelforum.com/member.php...o&userid=28934
View this thread: http://www.excelforum.com/showthread...hreadid=517572


Norman Jones

Toggle Code Calls
 
Hi Dave,

I am not sure that I understand, but perhaps:

Sub RunCode1()
MsgBox "Code1"
End Sub

Sub RunCode2()
MsgBox "Code2"
End Sub

Sub testoftoggle()
If Date #1/3/2006# = True Then
RunCode2
Else
RunCode1
End If
End Sub


---
Regards,
Norman



"Desert Piranha"
<Desert.Piranha.23yvvz_1141176602.7071@excelforu m-nospam.com wrote in
message news:Desert.Piranha.23yvvz_1141176602.7071@excelfo rum-nospam.com...

Hi all,

If these work, to call macro's:

Sub RunCode1()
Code1
End Sub

Sub RunCode2()
Code2
End Sub

Why dosen't this work, to toggle the calls?
Sub testoftoggle()
If Code1 = True Then
Code2
Else
Code1
End If
End Sub


--
Desert Piranha


------------------------------------------------------------------------
Desert Piranha's Profile:
http://www.excelforum.com/member.php...o&userid=28934
View this thread: http://www.excelforum.com/showthread...hreadid=517572




Tom Ogilvy

Toggle Code Calls
 
Because a sub can't return a value, so it can't have a value of True.

If it was a function and could, then you would have to run it to get that
value.

--
Regards,
Tom Ogilvy


"Desert Piranha"
<Desert.Piranha.23yvvz_1141176602.7071@excelforu m-nospam.com wrote in
message news:Desert.Piranha.23yvvz_1141176602.7071@excelfo rum-nospam.com...

Hi all,

If these work, to call macro's:

Sub RunCode1()
Code1
End Sub

Sub RunCode2()
Code2
End Sub

Why dosen't this work, to toggle the calls?
Sub testoftoggle()
If Code1 = True Then
Code2
Else
Code1
End If
End Sub


--
Desert Piranha


------------------------------------------------------------------------
Desert Piranha's Profile:

http://www.excelforum.com/member.php...o&userid=28934
View this thread: http://www.excelforum.com/showthread...hreadid=517572




Desert Piranha[_58_]

Toggle Code Calls
 

Hi Norman,

What i am trying to do is have one call, If i call it once it will call
Code1, If i call it again it will call Code2, If i call again it will
call code1, as in a toggle. But i don't have the code in there, They
are just a call to code elsewhere.

Yours would be what i am trying, without the date stuff.
Sub testoftoggle()
If Date #1/3/2006# = True Then
RunCode2
Else
RunCode1
End If
End Sub


Norman Jones Wrote:
Hi Dave,

I am not sure that I understand, but perhaps:

Sub RunCode1()
MsgBox "Code1"
End Sub

Sub RunCode2()
MsgBox "Code2"
End Sub

Sub testoftoggle()
If Date #1/3/2006# = True Then
RunCode2
Else
RunCode1
End If
End Sub


---
Regards,
Norman



"Desert Piranha"
<Desert.Piranha.23yvvz_1141176602.7071@excelforu m-nospam.com wrote in
message
news:Desert.Piranha.23yvvz_1141176602.7071@excelfo rum-nospam.com...

Hi all,

If these work, to call macro's:

Sub RunCode1()
Code1
End Sub

Sub RunCode2()
Code2
End Sub

Why dosen't this work, to toggle the calls?
Sub testoftoggle()
If Code1 = True Then
Code2
Else
Code1
End If
End Sub


--
Desert Piranha



------------------------------------------------------------------------
Desert Piranha's Profile:
http://www.excelforum.com/member.php...o&userid=28934
View this thread:

http://www.excelforum.com/showthread...hreadid=517572



--
Desert Piranha


------------------------------------------------------------------------
Desert Piranha's Profile: http://www.excelforum.com/member.php...o&userid=28934
View this thread: http://www.excelforum.com/showthread...hreadid=517572


Desert Piranha[_57_]

Toggle Code Calls
 

Hi Tom,
Thx for the input, I will look at a function.
Dave
Tom Ogilvy Wrote:
Because a sub can't return a value, so it can't have a value of True.

If it was a function and could, then you would have to run it to get
that
value.

--
Regards,
Tom Ogilvy


"Desert Piranha"
<Desert.Piranha.23yvvz_1141176602.7071@excelforu m-nospam.com wrote in
message
news:Desert.Piranha.23yvvz_1141176602.7071@excelfo rum-nospam.com...

Hi all,

If these work, to call macro's:

Sub RunCode1()
Code1
End Sub

Sub RunCode2()
Code2
End Sub

Why dosen't this work, to toggle the calls?
Sub testoftoggle()
If Code1 = True Then
Code2
Else
Code1
End If
End Sub


--
Desert Piranha



------------------------------------------------------------------------
Desert Piranha's Profile:

http://www.excelforum.com/member.php...o&userid=28934
View this thread:

http://www.excelforum.com/showthread...hreadid=517572



--
Desert Piranha


------------------------------------------------------------------------
Desert Piranha's Profile: http://www.excelforum.com/member.php...o&userid=28934
View this thread: http://www.excelforum.com/showthread...hreadid=517572


Norman Jones

Toggle Code Calls
 
Hi Dave,]

At the top of the code module, before any code, insert:

Public myToggle As Boolean

Then try:

Sub RunCode1()
MsgBox "Code1"
End Sub

Sub RunCode2()
MsgBox "Code2"
End Sub

Sub testoftoggle()
If myToggle Then
RunCode2
Else
RunCode1
End If
myToggle = Not myToggle
End Sub


---
Regards,
Norman



Norman Jones

Toggle Code Calls
 
Hi Dave,

Instead of using a public variable, you could also try:

Sub RunCode1()
MsgBox "Code1"
End Sub

Sub RunCode2()
MsgBox "Code2"
End Sub

Sub testoftoggle()
Static myToggle As Boolean
If myToggle Then
RunCode2
Else
RunCode1
End If
myToggle = Not myToggle
End Sub


---
Regards,
Norman



Tom Ogilvy

Toggle Code Calls
 
No, don't.

--
Regards,
Tom Ogilvy

"Desert Piranha"
<Desert.Piranha.23yxqn_1141179004.7216@excelforu m-nospam.com wrote in
message news:Desert.Piranha.23yxqn_1141179004.7216@excelfo rum-nospam.com...

Hi Tom,
Thx for the input, I will look at a function.
Dave
Tom Ogilvy Wrote:
Because a sub can't return a value, so it can't have a value of True.

If it was a function and could, then you would have to run it to get
that
value.

--
Regards,
Tom Ogilvy


"Desert Piranha"
<Desert.Piranha.23yvvz_1141176602.7071@excelforu m-nospam.com wrote in
message
news:Desert.Piranha.23yvvz_1141176602.7071@excelfo rum-nospam.com...

Hi all,

If these work, to call macro's:

Sub RunCode1()
Code1
End Sub

Sub RunCode2()
Code2
End Sub

Why dosen't this work, to toggle the calls?
Sub testoftoggle()
If Code1 = True Then
Code2
Else
Code1
End If
End Sub


--
Desert Piranha



------------------------------------------------------------------------
Desert Piranha's Profile:

http://www.excelforum.com/member.php...o&userid=28934
View this thread:

http://www.excelforum.com/showthread...hreadid=517572



--
Desert Piranha


------------------------------------------------------------------------
Desert Piranha's Profile:

http://www.excelforum.com/member.php...o&userid=28934
View this thread: http://www.excelforum.com/showthread...hreadid=517572




Desert Piranha[_59_]

Toggle Code Calls
 

Hi Tom,
No ,Don't <-- What? use a public variable?
Dave
Tom Ogilvy Wrote:
No, don't.

--
Regards,
Tom Ogilvy

"Desert Piranha"
<Desert.Piranha.23yxqn_1141179004.7216@excelforu m-nospam.com wrote in
message
news:Desert.Piranha.23yxqn_1141179004.7216@excelfo rum-nospam.com...

Hi Tom,
Thx for the input, I will look at a function.
Dave
Tom Ogilvy Wrote:
Because a sub can't return a value, so it can't have a value of

True.

If it was a function and could, then you would have to run it to

get
that
value.

--
Regards,
Tom Ogilvy


"Desert Piranha"
<Desert.Piranha.23yvvz_1141176602.7071@excelforu m-nospam.com wrote

in
message

news:Desert.Piranha.23yvvz_1141176602.7071@excelfo rum-nospam.com...

Hi all,

If these work, to call macro's:

Sub RunCode1()
Code1
End Sub

Sub RunCode2()
Code2
End Sub

Why dosen't this work, to toggle the calls?
Sub testoftoggle()
If Code1 = True Then
Code2
Else
Code1
End If
End Sub


--
Desert Piranha




------------------------------------------------------------------------
Desert Piranha's Profile:
http://www.excelforum.com/member.php...o&userid=28934
View this thread:
http://www.excelforum.com/showthread...hreadid=517572



--
Desert Piranha



------------------------------------------------------------------------
Desert Piranha's Profile:

http://www.excelforum.com/member.php...o&userid=28934
View this thread:

http://www.excelforum.com/showthread...hreadid=517572



--
Desert Piranha


------------------------------------------------------------------------
Desert Piranha's Profile: http://www.excelforum.com/member.php...o&userid=28934
View this thread: http://www.excelforum.com/showthread...hreadid=517572


Desert Piranha[_60_]

Toggle Code Calls
 

Hi Norman,

Both of your examples work great.

Thank you very much. I couldn't figure that one out.

Dave
Norman Jones Wrote:
Hi Dave,

Instead of using a public variable, you could also try:

Sub RunCode1()
MsgBox "Code1"
End Sub

Sub RunCode2()
MsgBox "Code2"
End Sub

Sub testoftoggle()
Static myToggle As Boolean
If myToggle Then
RunCode2
Else
RunCode1
End If
myToggle = Not myToggle
End Sub


---
Regards,
Norma


--
Desert Piranh

-----------------------------------------------------------------------
Desert Piranha's Profile: http://www.excelforum.com/member.php...fo&userid=2893
View this thread: http://www.excelforum.com/showthread.php?threadid=51757


Tom Ogilvy

Toggle Code Calls
 
Thx for the input, I will look at a function.

Too bad the Excel Forum isn't linear. It makes more sense in a Usenet
reader.

--
Regards,
Tom Ogilvy





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

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