Running a macro based on an IF

yoko

Active Member
Joined
Sep 5, 2006
Messages
349
Hi,

How can I get a macro to run based on an IF?

For example. If cell A1=1 then the macro will run.

Cheers.
 

Some videos you may like

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"

Peter_SSs

MrExcel MVP, Moderator
Joined
May 28, 2005
Messages
46,871
Office Version
  1. 365
Platform
  1. Windows
Hi,

How can I get a macro to run based on an IF?

For example. If cell A1=1 then the macro will run.

Cheers.
Investigate the Worksheet_Change event.

Post back if you need more detail.
 

yoko

Active Member
Joined
Sep 5, 2006
Messages
349
Ah excellent thanks a lot :biggrin:

Code:
Private Sub Worksheet_Change(ByVal Target As Excel.Range)

If Target.Address = "$A$1" Then
    Application.EnableEvents = False
    If Target.Value = 1 Then
         Range("A2").Value = "hello world"
    Else
       Range("A2").Value = ""
    End If
    Application.EnableEvents = True
End If

End Sub
 

Watch MrExcel Video

Forum statistics

Threads
1,114,090
Messages
5,545,897
Members
410,711
Latest member
Josh324
Top