[mso] Re: Using IF to select Macro command to carry out? Possible?

  • From: Wilson Baptista Junior <wilson@xxxxxxxxxx>
  • To: mso@xxxxxxxxxxxxx
  • Date: Wed, 18 May 2005 10:11:30 -0300

Hi Robert,
you can also run the macros without using the Run statement:

Sub ChooseMacroToRun ()
WhichMacro.value = Range("A6").value

Select Case WhichMacro
          Case 1
              FirstTrip
           Case2
               SecondTrip
                 (...)
Or, if your macros have arguments (doesn't seem to be the case), you 
can use the Call statement:

Sub ChooseMacroToRun ()
WhichMacro.value = Range("A6").value

Select Case WhichMacro
          Case 1
              Call FirstTrip(Argument1, Argument 2...)
          Case 2
              Call SecondTrip(Argument1, Argument 2...)
                 (...)

Wilson

At 22:27 17/5/2005,Robert Carneal wrote:
>Wilson, that looks very reasonable. The example in my book (which does not
>work!) uses this format:
>Select Case WhichMacro
>          Case 1
>              Do RunMacro(FirstTrip)
>          Case 2
>              Do RunMacro(SecondTrip)
>Etc........
>
>I will implement your suggestion tomorrow morning! I like it and it looks a
><cuss> better sample than my book gives!
>
>Thank you again.
>
>Robert
>
>
>
>-----Original Message-----
>From: mso-bounce@xxxxxxxxxxxxx [mailto:mso-bounce@xxxxxxxxxxxxx]On Behalf Of
>Wilson Baptista Junior
>Sent: Tuesday, May 17, 2005 8:01 PM
>To: mso@xxxxxxxxxxxxx
>Subject: [mso] Re: Using IF to select Macro command to carry out? Possible?
>
>Hi Robert,
>IMHO you will have to call the macros from VBA (inside another
>macro). One command you could use would be the Select Case command;
>you set a variable (for example, WhichMacro) to the value of cell A6,
>then the macro to run is chosen by code like this:
>
>Sub ChooseMacroToRun ()
>WhichMacro.value = Range("A6").value
>
>Select Case WhichMacro
>          Case 1
>              Run(FirstTrip)
>          Case 2
>              Run(SecondTrip)
>          Case 3
>              Run(ThirdTrip)
>          Case 4
>              Run(FourthTrip)
>          Case 5
>              Run(FifthTrip)
>          Case 6
>              Run(SixthTrip)
>          Case 7
>              Run(SeventhTrip)
>          Case Else
>              Do whatever you must do when the value is not from 1 to 7
>      End Select
>End Sub
>
>Now, to trigger the macro, you can assign it to a button for the user
>to click, or have it run automatically whenever the value of cell A6
>changes (for this, take a look at the Worksheet_SelectionChange event
>in Excel Help).
>Wilson
>
>
>
>At 17:11 17/5/2005,Robert Carneal wrote:
> >In Excel 2000, say I have five macro commands. I will call them Firsttrip,
> >Secondtrip, Thirdtrip, Fourthtrip, Fifthtrip, SixthTrip, SeventhTrip,
> >WrongTrip
> >
> >This is illegal in Excel, but please bear with me:
> >
> >A6=4
> >=Choose(A6, Firsttrip, Secondtrip, Thirdtrip, Fourthtrip, Fifthtrip,
> >SixthTrip, SeventhTrip)
> >
> >So whenever A6 is 4, run the macro FourthTrip. Possible? I can use Choose
> >with values and formulas, but what about macros?
>
>
>*************************************************************
>You are receiving this mail because you subscribed to mso@xxxxxxxxxxxxx or
>MicrosoftOffice@xxxxxxxxxxxxxxxx
>
>To send mail to the group, simply address it to mso@xxxxxxxxxxxxx
>
>To Unsubscribe from this group, send an email to
>mso-request@xxxxxxxxxxxxx with the word "unsubscribe" (without the quotes)
>in the subject line.
>
>Or, visit the group's homepage and use the dropdown menu.  This will also
>allow you to change your email settings to digest or vacation (no mail).
>//www.freelists.org/webpage/mso
>
>To be able to use the files section for sharing files with the group, send a
>request to mso-moderators@xxxxxxxxxxxxx and you will be sent an invitation
>with instructions.  Once you are a member of the files group, you can go
>here to upload/download files:
>http://www.smartgroups.com/vault/msofiles
>*************************************************************
>
>*************************************************************
>You are receiving this mail because you subscribed to 
>mso@xxxxxxxxxxxxx or MicrosoftOffice@xxxxxxxxxxxxxxxx
>
>To send mail to the group, simply address it to mso@xxxxxxxxxxxxx
>
>To Unsubscribe from this group, send an email to
>mso-request@xxxxxxxxxxxxx with the word "unsubscribe" (without the 
>quotes) in the subject line.
>
>Or, visit the group's homepage and use the dropdown menu.  This will 
>also allow you to change your email settings to digest or vacation (no mail).
>//www.freelists.org/webpage/mso
>
>To be able to use the files section for sharing files with the 
>group, send a request to mso-moderators@xxxxxxxxxxxxx and you will 
>be sent an invitation with instructions.  Once you are a member of 
>the files group, you can go here to upload/download files:
>http://www.smartgroups.com/vault/msofiles
>*************************************************************


*************************************************************
You are receiving this mail because you subscribed to mso@xxxxxxxxxxxxx or 
MicrosoftOffice@xxxxxxxxxxxxxxxx

To send mail to the group, simply address it to mso@xxxxxxxxxxxxx

To Unsubscribe from this group, send an email to 
mso-request@xxxxxxxxxxxxx with the word "unsubscribe" (without the quotes) in 
the subject line.

Or, visit the group's homepage and use the dropdown menu.  This will also allow 
you to change your email settings to digest or vacation (no mail).
//www.freelists.org/webpage/mso

To be able to use the files section for sharing files with the group, send a 
request to mso-moderators@xxxxxxxxxxxxx and you will be sent an invitation with 
instructions.  Once you are a member of the files group, you can go here to 
upload/download files:
http://www.smartgroups.com/vault/msofiles
*************************************************************

Other related posts: