+ Reply to Thread
Results 1 to 7 of 7

Initiate a macro in a cell

  1. #1
    Forum Contributor
    Join Date
    03-11-2018
    Location
    Tampa, Florida
    MS-Off Ver
    365
    Posts
    105

    Initiate a macro in a cell

    I know how to create a button and assign my macro to it. Click on the button and the macro runs. I'm wondering if I can initiate 1 of several macros based on values from other cells? For example let's say I click on my button, if C1 = 1 and D1 = 1, then macro A runs; if C1 = 5 and D1 = 2, macro B runs; if C1 = 11 and D1 = 1, macro C runs .... and so on.
    Last edited by 6StringJazzer; 04-30-2019 at 07:52 AM. Reason: Moved from Excel Formulas & Functions

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Initiate a macro in a cell

    When you say macro A, macro B, let's say you are talking about Subs. Your existing macro would look like this:

    Please Login or Register  to view this content.
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Registered User
    Join Date
    09-23-2010
    Location
    Cape Town, South Africa
    MS-Off Ver
    2007
    Posts
    14

    Re: Initiate a macro in a cell

    Scrap my comment, Stringer has got this

    regards,
    Murtadau
    Last edited by Murtadau_Gabier; 04-30-2019 at 07:58 AM.

  4. #4
    Forum Contributor
    Join Date
    03-11-2018
    Location
    Tampa, Florida
    MS-Off Ver
    365
    Posts
    105

    Re: Initiate a macro in a cell

    Thank you 6StringJazzer. I have a couple follow-up questions. Given that my existing macros are in separate modules:

    1) Do I need to use the "Public" and "Private" prefixes?
    2) Do I need to append my macro subs to your program as shown above or will your program call them from the separate modules?

  5. #5
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Initiate a macro in a cell

    Hi dvess,

    Clearly 6StringJazzer has this under control, I was just browsing... but can quickly answer your questions. If a sub has "Private" as its prefix, it can't be called from another Module. If your macros are not in Private subs, then they can stay where they are, and will run just fine if you just put his code into any module (existing OR new).
    Please help by:

    Marking threads as closed once your issue is resolved. How? The Thread Tools at the top
    Any reputation (*) points appreciated. Not just by me, but by all those helping, so if you found someone's input useful, please take a second to click the * at the bottom left to let them know

    There are 10 kinds of people in this world... those who understand binary, and those who don't.

  6. #6
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Initiate a macro in a cell

    To just add to Arkadi's explanation, the default is Public, and you can move things around and make anything Public if you have things in different modules. You don't have to do it exactly the way I showed. That is the answer to VBA coding semantics.

    Whether things should be in the same or different modules is a design issue, but I don't know your big picture.

  7. #7
    Forum Contributor
    Join Date
    03-11-2018
    Location
    Tampa, Florida
    MS-Off Ver
    365
    Posts
    105

    Re: Initiate a macro in a cell

    Thanks guys. Everything is working well.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. initiate a macro upon keystroke combination
    By prabhuduraraj09 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-17-2017, 03:11 PM
  2. Worksheet_Change Event - How to initiate a Macro?
    By Jimbo42 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-25-2013, 09:01 PM
  3. Initiate a macro in one workbook and have it run in 4 other workbooks
    By Delta in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-08-2012, 08:54 PM
  4. Initiate Macro
    By bartinp in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-05-2009, 11:35 AM
  5. Macro to initiate on a cell's change in value
    By GuruWannaB in forum Excel General
    Replies: 6
    Last Post: 11-11-2008, 02:06 PM
  6. [SOLVED] How do I initiate a macro directly in a worksheet?
    By AMMPro in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-15-2006, 06:05 PM
  7. Initiate Macro On Save
    By JTWood in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-14-2006, 10:47 AM

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.6.0 RC 1