+ Reply to Thread
Results 1 to 8 of 8

Run macro in IF function

  1. #1
    Registered User
    Join Date
    02-17-2013
    Location
    Richmond, VA
    MS-Off Ver
    Excel 2010
    Posts
    9

    Run macro in IF function

    =IF($A$11=1,"macro1","Macro2")

    What is the code for the above if I want a respective macro -- in my example, macro 1 to run if A11 has a 1 and macro 2 to run if different value?

    Thanks.

  2. #2
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Run macro in IF function

    Please Login or Register  to view this content.
    Last edited by AB33; 02-23-2013 at 04:18 PM.

  3. #3
    Valued Forum Contributor
    Join Date
    06-19-2010
    Location
    Holywell, N Wales, UK
    MS-Off Ver
    Excel 2013
    Posts
    470

    Re: Run macro in IF function

    OOPs and with acknowledgements to AB33 - just in case the shorthand/psuedo code confuses,
    perhaps variations on the following
    Please Login or Register  to view this content.
    or
    Please Login or Register  to view this content.
    or
    Please Login or Register  to view this content.
    Last edited by barryleajo; 02-23-2013 at 04:53 PM. Reason: typos
    If this was helpful then please click the small star icon at the bottom left of my post. A little appreciation goes a long way.

  4. #4
    Registered User
    Join Date
    02-17-2013
    Location
    Richmond, VA
    MS-Off Ver
    Excel 2010
    Posts
    9

    Re: Run macro in IF function

    Thanks --so can run a macro within an IF type function -- my actual situation is a somewhat more complicated -- have 6 choices for cell A11 -- 1a,1b,2a,2b,3a,3b. Depending on the contents of A11 a different macro is run. Can I do this and if so How?

    Thanks again.

  5. #5
    Valued Forum Contributor
    Join Date
    06-19-2010
    Location
    Holywell, N Wales, UK
    MS-Off Ver
    Excel 2013
    Posts
    470

    Re: Run macro in IF function

    Perhaps a variation on this to suit your requirements?
    Please Login or Register  to view this content.
    Last edited by barryleajo; 02-23-2013 at 04:50 PM. Reason: typo

  6. #6
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,810

    Re: Run macro in IF function

    =IF($A$11=1,"macro1","Macro2")
    The only way this really works is if "macro1" and "macro2" are written as user-defined functions (A VBA function procedure that is written so it can be called directly from an Excel cell like Excel's built in functions). UDF's can perform calculations and return values to the cell(s) they are called from, but they cannot perform actions like deleting, formatting, copying, etc. You haven't specified what "macro1" and "macro2" do. If they are computing a value so that they can be set up as UDFs, then you should be able to use them like you are suggesting. If they are doing other things, then you will need code like the other responses have suggested - your VBA procedure will have to test the condition and call macro1 and macro2 accordingly.
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

  7. #7
    Registered User
    Join Date
    02-23-2013
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    8

    Re: Run macro in IF function

    Hi,

    I have read the reply and just wondered if the same expert can help me with similar enquiry:

    If I want to copy cell A to a new line of a new worksheet when "option a" is selected/entered for cell B of the same record?

    Await your advice,
    thanks

  8. #8
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Run macro in IF function

    Felicia, please start your own thread.
    Entia non sunt multiplicanda sine necessitate

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