can i use an IF Statement to run a macro?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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.
 
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top