Initiating a Macro

S

Setts

I would like to initiate a macro when a cell has a specific value or
satisfies a formula (e.g. A>B). Is that possible? Thanks in advance. JS
 
M

Mike H

Hi,

You could use the worksheet change event. Right click your sheet tab, view
code and paste this in

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Cells.Count > 1 Or IsEmpty(Target) Then Exit Sub
If Target.Address = "$A$1" Then
If IsNumeric(Target) Then
On Error Resume Next
Application.EnableEvents = False
If Target.Value > Range("B1").Value Then
'do your thing
End If
Application.EnableEvents = True
On Error GoTo 0
End If
End If
End Sub

Now if A1 changes to a value greater than B1 you can run some code.

Mike
 

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

Top