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
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
Thx
Dave
"The game is afoot Watson"
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"
<[email protected]> wrote in
message news:[email protected]...
>
> 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
>
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"
<[email protected]> wrote in
message news:[email protected]...
>
> 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
>
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
Originally Posted by Norman Jones
Hi Tom,
Thx for the input, I will look at a function.
Dave
Originally Posted by Tom Ogilvy
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
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
No, don't.
--
Regards,
Tom Ogilvy
"Desert Piranha"
<[email protected]> wrote in
message news:[email protected]...
>
> 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"
> > <[email protected]> wrote in
> > message
> > news:[email protected]...
> > >
> > > 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
>
Hi Tom,
No ,Don't <-- What? use a public variable?
Dave
Originally Posted by Tom Ogilvy
Hi Norman,
Both of your examples work great.
Thank you very much. I couldn't figure that one out.
Dave
Originally Posted by Norman Jones
>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
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks