+ Reply to Thread
Results 1 to 8 of 8

can i use an IF Statement to run a macro?

  1. #1
    Davidrowland88
    Guest

    can i use an IF Statement to run a macro?

    i am using excel 2000. I want to know if you can use an IF Statement to run a
    macro. E.G If a cell equals 1 then run a certain macro

  2. #2
    JE McGimpsey
    Guest

    Re: can i use an IF Statement to run a macro?

    No, in general, formulas can only return values to their calling cells.
    However, you can use an event macro that will check your cell each time
    the sheet is calculated, say, and run the macro if the value of the cell
    is 1. Put this in your worksheet code module (right-click the worksheet
    tab and choose View Code):

    Private Sub Worksheet_Calculate()
    If Range("A1").Value = 1 Then MyMacro
    End Sub

    where MyMacro is the name of your macro.


    In article <[email protected]>,
    "Davidrowland88" <[email protected]> wrote:

    > i am using excel 2000. I want to know if you can use an IF Statement to run a
    > macro. E.G If a cell equals 1 then run a certain macro


  3. #3
    Ron Rosenfeld
    Guest

    Re: can i use an IF Statement to run a macro?

    On Fri, 11 Feb 2005 04:25:02 -0800, "Davidrowland88"
    <[email protected]> wrote:

    >i am using excel 2000. I want to know if you can use an IF Statement to run a
    >macro. E.G If a cell equals 1 then run a certain macro


    By IF statement I assume you mean the IF worksheet function; and not an IF
    statement within the macro itself.

    Probably not as a worksheet function cannot change another cell.

    However, you could set up your macro as an event-triggered macro, and within
    the macro test to see if the cell equals 1.


    --ron

  4. #4
    Registered User
    Join Date
    04-21-2019
    Location
    Urbana, Ohio
    MS-Off Ver
    2010
    Posts
    2

    Re: can i use an IF Statement to run a macro?

    Sub Macro1()

    If Not Range("A1") = "1" Then
    Exit Sub
    ElseIf Range("A1") = "1" Then
    Application.Run ("Macro2")
    End IF
    End Sub

    Not sure if this works on 2000 but does on 2010.

  5. #5
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,917

    Re: can i use an IF Statement to run a macro?

    AppleUSN welcome to the forum and thanks for the input
    (did you notice that this thread is almost 15 years old?)
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

  6. #6
    Registered User
    Join Date
    04-21-2019
    Location
    Urbana, Ohio
    MS-Off Ver
    2010
    Posts
    2

    Re: can i use an IF Statement to run a macro?

    Thanks for the welcome and I sure did notice. I did not find the answer I was looking for when I was searching for this coding but I noticed this thread in my search on google. I fgured if someone else like me was searching for this code in the future then maybe they would find my answer. Always good to have an answer for others where the question posed is closely related to what the thread was asking. Except in this case the thread just said it can’t happen. Well, maybe not in 2000, but in 2010 you can.

  7. #7
    Registered User
    Join Date
    11-05-2019
    Location
    Michigan
    MS-Off Ver
    2013
    Posts
    6

    Re: can i use an IF Statement to run a macro?

    I have been searching for hours trying to accomplish this simple task that I would have thought would have been done long ago. I have a spreadsheet on which I want to hide most of the bottom rows to reduce eye clutter. I want to automatically unhide one row at a time when I enter anything into the cell two rows above. When I enter anything at all in the cell, the cursor will drop to the row below when I hit enter. That line will already be unhidden, but when I hit enter, I want the row two rows below to automatically unhide.

    I can do it with your info, but my question is what causes Macro1 to run? I want entering data into my target cell to execute Macro1, which will call Macro2 to unhide the proper row.

  8. #8
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,917

    Re: can i use an IF Statement to run a macro?

    Quote Originally Posted by LRGoodger View Post
    I have been searching for hours trying to accomplish this simple task that I would have thought would have been done long ago. I have a spreadsheet on which I want to hide most of the bottom rows to reduce eye clutter. I want to automatically unhide one row at a time when I enter anything into the cell two rows above. When I enter anything at all in the cell, the cursor will drop to the row below when I hit enter. That line will already be unhidden, but when I hit enter, I want the row two rows below to automatically unhide.

    I can do it with your info, but my question is what causes Macro1 to run? I want entering data into my target cell to execute Macro1, which will call Macro2 to unhide the proper row.
    Administrative Note:

    Welcome to the forum.

    We are happy to help, however whilst you feel your request is similar to this thread, experience has shown that things soon get confusing when answers refer to particular cells/ranges/sheets which are unique to your post and not relevant to the original.

    Please see Forum Rule #4 about hijacking and start a new thread for your query.

    If you are not familiar with how to start a new thread see the FAQ: How to start a new thread

+ 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