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
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
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
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
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.
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
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.
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
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks