Running a macro when selecting an item in a drop-down list

  • Thread starter Thread starter Christine
  • Start date Start date
C

Christine

Could someone provide me with the code to run macro "MyMacro" when an item is
selected from a drop-down list located in cell H4?

Chris
 
Right click the workhseet tab with the drop down in it and select view code.
Paste the following...

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$H$4" Then Call MyMacro
End Sub
 
Beautiful! Thank you very much, Jim.

Jim Thomlinson said:
Right click the workhseet tab with the drop down in it and select view code.
Paste the following...

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$H$4" Then Call MyMacro
End Sub
 
Any item will run the macro or certain items will run certain macros?

This worksheet change event will run MyMacro whenever any item is picked
from the DV dropdown.

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Cells.Count > 1 Then Exit Sub
If Intersect(Target, Me.Range("H4")) Is Nothing Then Exit Sub
On Error GoTo CleanUp
Application.EnableEvents = False
With Target
If .Value <> "" Then
MyMacro
End If
End With
CleanUp:
Application.EnableEvents = True
End Sub


Gord Dibben MS Excel MVP
 
Thank you, Gord. I'll try your code as well.

Gord Dibben said:
Any item will run the macro or certain items will run certain macros?

This worksheet change event will run MyMacro whenever any item is picked
from the DV dropdown.

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Cells.Count > 1 Then Exit Sub
If Intersect(Target, Me.Range("H4")) Is Nothing Then Exit Sub
On Error GoTo CleanUp
Application.EnableEvents = False
With Target
If .Value <> "" Then
MyMacro
End If
End With
CleanUp:
Application.EnableEvents = True
End Sub


Gord Dibben MS Excel MVP
 
Back
Top