+ Reply to Thread
Results 1 to 10 of 10

Thread: Have Macro determine which Macro to run.

  1. #1
    Registered User
    Join Date
    03-12-2009
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    8

    Have Macro determine which Macro to run.

    Here is the scenario. I have a template that other users fill out and I run a macro based on the data that they populate in the template. I have three destinations for this data depending on how a particular cell is coded (validation list box with three choices). Currently I have to determine the how the cell is coded and run the corresponding macro. I would like to have one overall macro that can look at the cell with the coding and determine which of the three macros to run and then execute that macro. I was originally thinking of something like an If/Else statement, but that will only work if there are two options. Is there something else that I could use that will make this work?
    Last edited by Jeff_J; 03-13-2009 at 12:15 PM.

  2. #2
    Forum Guru VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    12,010

    Re: Have Macro determine which Macro to run.

    A worksheet change macro would work.

    What the
    • 3 key words
    • names of the 3 macro's
    • Cell that the validation list is in
    VBA Noob
    _________________________________________


    Credo Elvem ipsum etian vivere
    _________________________________________
    A message for cross posters

    Please remember to wrap code.

    Forum Rules

    Please add to your signature if you found this link helpful. Excel links !!!

  3. #3
    Registered User
    Join Date
    03-12-2009
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: Have Macro determine which Macro to run.

    I am not familiar with the working with that function, so I don’t think that it will work. Maybe I explain this further too.

    The user takes the template and saves it (File A). I then open up File A and run a macro that transfer information into File B. Now depending again on the cell is coded in File A, it will take one of three macros to transfer this information. I do not need to save either File A or File B with a different name nor do I want to change the sheet names within either workbook.

    Thanks for the help and I will look into that function some more as well.

  4. #4
    Forum Guru VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    12,010

    Re: Have Macro determine which Macro to run.

    I am not familiar with the working with that function, so I don’t think that it will work
    If you're not familiar then how do you know it won't work

    The user takes the template and saves it (File A). I then open up File A and run a macro that transfer information into File B. Now depending again on the cell is coded in File A, it will take one of three macros to transfer this information. I do not need to save either File A or File B with a different name nor do I want to change the sheet names within either workbook.
    a proper a example would be more helpful

    VBA Noob
    _________________________________________


    Credo Elvem ipsum etian vivere
    _________________________________________
    A message for cross posters

    Please remember to wrap code.

    Forum Rules

    Please add to your signature if you found this link helpful. Excel links !!!

  5. #5
    Forum Guru mudraker's Avatar
    Join Date
    11-10-2003
    Location
    Melbourne, Australia
    Posts
    3,984

    Re: Have Macro determine which Macro to run.

    I was originally thinking of something like an If/Else statement, but that will only work if there are two options
    You can have more than 2 options using If statements

    I suggest in a module shhet you type in IF hit F1 to bring up the help file

    I also suggest you look at Select Case commands

    PS - If you do not understand a suggestion in a reply I recomend you follow up by asking more questions or reading up on the commands etc.
    Don't just say you
    so I don’t think that it will work
    Using comments like that is a good way to have helpful people ignore your requests for help as it appears you will ignore what is suggested to you.

    If you do feel something will not work and you have a valid reason beside
    I am not familiar with the working with that function
    then do reply listing your reasons & concerns as to why you think it will not work


    Based on your request Rok's suggestion of a worksheet change macro would work
    Please Read Forum Rules Before Posting
    Wrap VBA code by selecting the code and clicking the # icon or Read This
    How To Cross Post politely

    Top Excel links for beginners to Experts

    If you are pleased with a member's answer then use the Scales icon to rate it
    If my reply has assisted or failed to assist you I welcome your Feedback.

  6. #6
    Registered User
    Join Date
    03-12-2009
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: Have Macro determine which Macro to run.

    Alright, here is what I have. It does not run any of the macros though any thoughts?
    Sub Jeff()
    If "A20" = "Parts Sale" Then
            Call PackingSlipToParts_SaleQue
        ElseIf A20 = "Warranty" Then
            Call PackingSlipToWarrantyQue
        ElseIf A20 = "Trailer Sale" Then
            Call PackingSlipToTrailerSaleQue
        End If
    End Sub
    Last edited by Jeff_J; 03-13-2009 at 12:14 PM.

  7. #7
    Forum Guru mudraker's Avatar
    Join Date
    11-10-2003
    Location
    Melbourne, Australia
    Posts
    3,984

    Re: Have Macro determine which Macro to run.

    Please take a couple of minutes and read ALL theForum Rules then wrap your VBA code (Rule 3)
    Please Read Forum Rules Before Posting
    Wrap VBA code by selecting the code and clicking the # icon or Read This
    How To Cross Post politely

    Top Excel links for beginners to Experts

    If you are pleased with a member's answer then use the Scales icon to rate it
    If my reply has assisted or failed to assist you I welcome your Feedback.

  8. #8
    Registered User
    Join Date
    03-12-2009
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: Have Macro determine which Macro to run.

    Here is the functional code.
    Sub MasterPackingSlip()
    
    Dim R As String
    
    Cells.Range("A20").Activate
    R = ActiveCell.Value
    If R = "Parts Sale" Then
            Call PackingSlipToParts_SaleQue
        ElseIf R = "Warranty" Then
            Call PackingSlipToWarrantyQue
        ElseIf R = "Trailer Sale Parts" Then
            Call PackingSlipToTrailerSaleQue
        End If
    
    End Sub
    So the answer to my question was..
    Quote Originally Posted by mudraker View Post
    You can have more than 2 options using If statements

    I suggest in a module shhet you type in IF hit F1 to bring up the help file
    work
    Thank you for those that helped.
    Last edited by Jeff_J; 03-13-2009 at 12:14 PM.

  9. #9
    Registered User
    Join Date
    03-12-2009
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: Have Macro determine which Macro to run.

    Done adding wrap
    Last edited by Jeff_J; 03-13-2009 at 12:16 PM.

  10. #10
    Forum Guru, retired Admin royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    25,639

    Re: Have Macro determine which Macro to run.

    Try
    Option Explicit
    
    Sub MasterPackingSlip()
        Select Case Range("A20").Value
            Case "Parts Sale": Call PackingSlipToParts_SaleQue
            Case "Warranty": Call PackingSlipToWarrantyQue
            Case "Trailer Sale Parts": Call PackingSlipToTrailerSaleQue
            Case Else: Exit Sub
        End Select
    End Sub
    Last edited by royUK; 03-14-2009 at 03:43 AM.
    Hope that helps.

    RoyUK
    --------
    If you are pleased with a member's answer then use the Star icon to rate it, if you are pleased enough to part with cash consider a donation to Children in Need

    For Excel Tips & Solutions, free examples and tutorials why not check out my downloads

    New members please read & follow the Forum Rules

    Remember to mark your questions Solved and rate the answer(s)

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.2.0