how can i use an if statement to run a macro?

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

Guest

if ( a1 = 1, run macro, " ")

what code do i need to use to do this?
 
Insert this code into your sheet and you should be good to go.

Option Explicit

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$A$1" And Target.Value = 1 Then
Call MyMacro 'Insert the name of your macro here
End If
End Sub

To add this to a sheet right click on the sheet tab -> select view code
->paste

HTH
 
Are you talkong about a worksheet formula that looks like what you posted? If
so, you can't "run a macro" that carries out actions on the worksheet.

The "macro" can only be a VBA function that returns a value to the cell, just
like SUM or AVERAGE do.
 

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