Inserting a Macro into an IF statement?

  • Thread starter Thread starter greyfox45
  • Start date Start date
G

greyfox45

I have created a macro that I would like to insert into an I
statement.

For example.

If cell A2 = 1, then I want the macro to run.

Can someone help me figure this out? It is very important that
figure this out and probably simple for you to answer
 
Try something like this

If Cells(2, 1) = 1 Then
' put your macro here
End If


--
Paul B
Always backup your data before trying something new
Please post any response to the newsgroups so others can benefit from it
Feedback on answers is always appreciated!
Using Excel 2000 & 97
** remove news from my email address to reply by email **
 
this ONE liner should do it for you

if range("a2")=1 then call mymacro'(use the name of your macro)
 
alright. I tried this stuff but couldn't get it working.

here is how my IF statement appears:

=IF(C1=1,call mymacro(tnarg))
it says that the following was an invalid formula. (my macro is named
tnarg)
 
then modify what I sent
if range("a2")=1 then call mymacro'(use the name of your macro)
to
if range("c1")=1 then call tnarg
You don't write macros like formulas. AND, this must be put in a module and
executed from there. AND, as written you must have the sheet where c1 is as
the active sheet or add the sheet to the IF
if sheets("yoursheetnamehere").range("c1")=1 then call tnarg

Formulas can NOT call macros. But, you can create a worksheet_change event
to do that.
Right click sheet tab>view code>insert this. Now automatic
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$C$1" Then Call tnarg
End Sub
 
should be
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$C$1" and target=1 Then Call tnarg
End Sub


--
Don Guillett
SalesAid Software
(e-mail address removed)
Don Guillett said:
then modify what I sent
if range("a2")=1 then call mymacro'(use the name of your macro)
to
if range("c1")=1 then call tnarg
You don't write macros like formulas. AND, this must be put in a module and
executed from there. AND, as written you must have the sheet where c1 is as
the active sheet or add the sheet to the IF
if sheets("yoursheetnamehere").range("c1")=1 then call tnarg

Formulas can NOT call macros. But, you can create a worksheet_change event
to do that.
Right click sheet tab>view code>insert this. Now automatic
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$C$1" Then Call tnarg
End Sub
 
Back
Top