A Microsoft Excel forum. ExcelBanter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » ExcelBanter forum » Excel Newsgroups » Excel Discussion (Misc queries)
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

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



 
 
Thread Tools Display Modes
  #1  
Old August 1st 08, 07:10 PM posted to microsoft.public.excel.misc
Christine
external usenet poster
 
Posts: 147
Default Running a macro when selecting an item in a drop-down list

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
Ads
  #2  
Old August 1st 08, 07:52 PM posted to microsoft.public.excel.misc
Jim Thomlinson
external usenet poster
 
Posts: 5,942
Default Running a macro when selecting an item in a drop-down list

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
--
HTH...

Jim Thomlinson


"Christine" wrote:

> 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

  #3  
Old August 1st 08, 08:03 PM posted to microsoft.public.excel.misc
Christine
external usenet poster
 
Posts: 147
Default Running a macro when selecting an item in a drop-down list

Beautiful! Thank you very much, Jim.

"Jim Thomlinson" wrote:

> 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
> --
> HTH...
>
> Jim Thomlinson
>
>
> "Christine" wrote:
>
> > 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

  #4  
Old August 1st 08, 08:24 PM posted to microsoft.public.excel.misc
Gord Dibben
external usenet poster
 
Posts: 22,911
Default Running a macro when selecting an item in a drop-down list

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

On Fri, 1 Aug 2008 11:10:00 -0700, Christine
> wrote:

>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


  #5  
Old August 1st 08, 08:50 PM posted to microsoft.public.excel.misc
Christine
external usenet poster
 
Posts: 147
Default Running a macro when selecting an item in a drop-down list

Thank you, Gord. I'll try your code as well.

"Gord Dibben" wrote:

> 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
>
> On Fri, 1 Aug 2008 11:10:00 -0700, Christine
> > wrote:
>
> >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

>
>

 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to link macro to change an item in drop-down list Amotif Excel Discussion (Misc queries) 1 May 7th 08 01:55 PM
Selecting an item from a list [email protected][_2_] New Users to Excel 1 October 9th 07 05:50 PM
Running a macro for each item in an Autofilter list Andrew Excel Discussion (Misc queries) 1 August 19th 05 02:39 PM
changing value of a cell by selecting an item from a drop down list Bobby Mir Excel Worksheet Functions 6 June 8th 05 08:33 PM
Selecting an Item from a List and getting a different item to pop. Matt Excel Worksheet Functions 1 December 7th 04 02:37 PM


All times are GMT +1. The time now is 12:54 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Copyright 2004-2014 ExcelBanter.
The comments are property of their posters.