Thread: [Solved] Run Macro
View Single Post
 
Old 05-11-2012, 07:59 PM
macropod's Avatar
macropod macropod is offline Windows 7 64bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,467
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Hi ibrahimaa,

You could use a 'Worksheet_SelectionChange' macro like the following in the relevant worksheet's code module:
Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
If Target.Address = "$A$3" Then
  If Target.Value = 123 Then
    Application.EnableEvents = False
    'Call your other macro here
    Application.EnableEvents = True
  End If
End If
End Sub
In the above example, your macro will be called if cell A3 is selected and its value is 123. Note that merely selecting the cell when it has this value will be enough to trigger the macro. If you don't want that, you might prefer to use the 'Worksheet_Calculate' event. That event, though, won't be triggered by inputting anything into the cell unless that results in the worksheet re-calculating.
Code:
Private Sub Worksheet_Calculate()
If ActiveCell.Address = "$A$3" Then
  If ActiveCell.Value = 123 Then
    Application.EnableEvents = False
    'Call your other macro here
    Application.EnableEvents = True
  End If
End If
End Sub
You'll note that, in both case, I've included some Application.EnableEvents lines. Depending on what you're doing you may or may not need these.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote