+ Reply to Thread
Results 1 to 3 of 3

Thread: Call macro - Possible to use macro name from cell?

  1. #1
    Registered User
    Join Date
    05-12-2009
    Location
    Udevalla, Sweden
    MS-Off Ver
    Excel 2003
    Posts
    73

    Call macro - Possible to use macro name from cell?

    Hi.

    First of all, thanks to all the guys here who regularly help excel n00bs like me. How you get the time to do it, I will never know.


    Okay.

    My question: Is it possible to write a code that calls the macro with the name specified in a particular cell?
    Right now I have some AutoFilter going on making a list that has
    numbers 1, 2, 3...
    I also have alot of macros named Search1, Search2, Search3...

    So I can make a cell, say A28, that combines "Search" with whatever number is in Column C, row 29:

    = "Search" & C29

    Now I want to make a commandbutton that calls a macro depending on what the value of A28 is.

    So if the AutoFilter should give me a list that has the value 25 in C29, then pressing the commandbutton should call the macro named Search25.
    I attached a dummy workbook you can work on.

    Dont worry about how the value in C29 is generated. Just know that it changes value depending on an AutoFiltered list elsewhere in the workbook.


    Okay. This description turned out to be a bit longer than I expected Hopefully everything is clear.

    I have tried some stuff like:

    Dim sPrjct As String
        sPrjct = Sheets("Interface").Range("A28").Value
    
    Call sPrjct
    Didnt work...
    I am the worst VBA n00b there is


    Any help on this would be greatly appreciated
    Attached Files Attached Files
    Last edited by Carlsbergen; 09-30-2009 at 07:50 AM.

  2. #2
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    Apparently I can't say
    MS-Off Ver
    Apparently I can't say
    Posts
    8,274

    Re: Call macro - Possible to use macro name from cell?

    You can use application.run:
    Application.Run sPrjct
    but I suspect from your description that there are probably better methods. Do you actually need lots of different search macros or could you use one macro with a few variables in it?

  3. #3
    Registered User
    Join Date
    05-12-2009
    Location
    Udevalla, Sweden
    MS-Off Ver
    Excel 2003
    Posts
    73

    Re: Call macro - Possible to use macro name from cell?

    Quote Originally Posted by romperstomper View Post
    You can use application.run:
    Application.Run sPrjct
    but I suspect from your description that there are probably better methods. Do you actually need lots of different search macros or could you use one macro with a few variables in it?
    That worked great! Thnx

    You're probably right in that I could have made something more efficient than using a different macro for each "search".
    I didnt know about this forum when I started making it and this was the only way I could think of doing it then
    Next time!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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