Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default ListBox Selection to fire Macro


Hi - Is it possible to have a dropdown box (listbox/combobox?) of 13
text choices, with each choice assigned to a macro?

Ideally I'd like to run one of 13 macros depending upon what the user
selects from this dropdown box.

My present method is using 13 checkboxes with a different macro
assigned to each - the user ticks it, and my macro fires. This though
is occupies too much screen area.

Any help would be appreciated.

Regards Kaye

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 55
Default ListBox Selection to fire Macro

Kaye,

You can use data validation in the cell, with a list of your 13 choices.
Then in that sheet's code module insert a Worksheet_Change Event module.
Assuming your data validated cell is in A1 and your choices are "a", "b" and
"c" you could use code like this:

Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("A1")) Is Nothing Then
Select Case Range("A1").Value
Case "a"
Call MacroA
Case "b"
Call MacroB
Case "c"
Call MacroC
End Select
End If
End Sub

hth,

Doug

"Kaye" wrote in message
...

Hi - Is it possible to have a dropdown box (listbox/combobox?) of 13
text choices, with each choice assigned to a macro?

Ideally I'd like to run one of 13 macros depending upon what the user
selects from this dropdown box.

My present method is using 13 checkboxes with a different macro
assigned to each - the user ticks it, and my macro fires. This though
is occupies too much screen area.

Any help would be appreciated.

Regards Kaye



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default ListBox Selection to fire Macro

Thanks for that Doug, that's what I was after!

But - another small problem has come to light ....

I have TWO cells that carry Data Validation list boxes - A1, and also
at A2, just beneath it.

It appears I can't have TWO "Worksheet_Change" macros on the same
sheet, even though my "Target, Range" is a different cell, that being
A2 rather than A1.

Is there any way I can have TWO "Worksheet_Change" macros on the same
sheet?

Kaye


On Mon, 19 Feb 2007 19:10:50 -0800, "Doug Glancy"
wrote:

Kaye,

You can use data validation in the cell, with a list of your 13 choices.
Then in that sheet's code module insert a Worksheet_Change Event module.
Assuming your data validated cell is in A1 and your choices are "a", "b" and
"c" you could use code like this:

Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("A1")) Is Nothing Then
Select Case Range("A1").Value
Case "a"
Call MacroA
Case "b"
Call MacroB
Case "c"
Call MacroC
End Select
End If
End Sub

hth,

Doug

"Kaye" wrote in message
.. .

Hi - Is it possible to have a dropdown box (listbox/combobox?) of 13
text choices, with each choice assigned to a macro?

Ideally I'd like to run one of 13 macros depending upon what the user
selects from this dropdown box.

My present method is using 13 checkboxes with a different macro
assigned to each - the user ticks it, and my macro fires. This though
is occupies too much screen area.

Any help would be appreciated.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 770
Default ListBox Selection to fire Macro

Kaye,

You can't have two Worksheet_Change events, but in your single event you can
test for each cell separately. Duplicate the code for A2 so that it looks
something like this:

Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("A1")) Is Nothing Then
Select Case Range("A1").Value
Case "a"
Call MacroA
Case "b"
Call MacroB
Case "c"
Call MacroC
End Select
If Not Intersect(Target, Range("A2")) Is Nothing Then
Select Case Range("A2").Value
Case "1"
Call Macro1
Case "2"
Call Macro2
Case "3"
Call Macro3
End Select
End If
End Sub

The above assumes that the validation for A2 is different. But if it's the
same, just modify it back to the "A" "B" and "C" values.

hth,

Doug

"Kaye" wrote in message
...
Thanks for that Doug, that's what I was after!

But - another small problem has come to light ....

I have TWO cells that carry Data Validation list boxes - A1, and also
at A2, just beneath it.

It appears I can't have TWO "Worksheet_Change" macros on the same
sheet, even though my "Target, Range" is a different cell, that being
A2 rather than A1.

Is there any way I can have TWO "Worksheet_Change" macros on the same
sheet?

Kaye


On Mon, 19 Feb 2007 19:10:50 -0800, "Doug Glancy"
wrote:

Kaye,

You can use data validation in the cell, with a list of your 13 choices.
Then in that sheet's code module insert a Worksheet_Change Event module.
Assuming your data validated cell is in A1 and your choices are "a", "b"
and
"c" you could use code like this:

Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("A1")) Is Nothing Then
Select Case Range("A1").Value
Case "a"
Call MacroA
Case "b"
Call MacroB
Case "c"
Call MacroC
End Select
End If
End Sub

hth,

Doug

"Kaye" wrote in message
. ..

Hi - Is it possible to have a dropdown box (listbox/combobox?) of 13
text choices, with each choice assigned to a macro?

Ideally I'd like to run one of 13 macros depending upon what the user
selects from this dropdown box.

My present method is using 13 checkboxes with a different macro
assigned to each - the user ticks it, and my macro fires. This though
is occupies too much screen area.

Any help would be appreciated.



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default ListBox Selection to fire Macro

Thanks Doug, but I'm having a problem.

Yes, you are correct in your assumption that the validation for A2 is
different.

When I run this new code, from A1 or A2, this is returned:
"Compile Error: Block IF without ENDIF"

The last line of the code, END SUB, is highlighted blue, and
the first line, "Private sub Worksheet_Change etc is highlighted
yellow.

I've transposed your code correctly. Any clues?

Regards, Kaye

On Tue, 20 Feb 2007 16:39:27 -0800, "Doug Glancy"
wrote:

Kaye,

You can't have two Worksheet_Change events, but in your single event you can
test for each cell separately. Duplicate the code for A2 so that it looks
something like this:

Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("A1")) Is Nothing Then
Select Case Range("A1").Value
Case "a"
Call MacroA
Case "b"
Call MacroB
Case "c"
Call MacroC
End Select
If Not Intersect(Target, Range("A2")) Is Nothing Then
Select Case Range("A2").Value
Case "1"
Call Macro1
Case "2"
Call Macro2
Case "3"
Call Macro3
End Select
End If
End Sub

The above assumes that the validation for A2 is different. But if it's the
same, just modify it back to the "A" "B" and "C" values.

hth,

Doug

"Kaye" wrote in message
.. .
Thanks for that Doug, that's what I was after!

But - another small problem has come to light ....

I have TWO cells that carry Data Validation list boxes - A1, and also
at A2, just beneath it.

It appears I can't have TWO "Worksheet_Change" macros on the same
sheet, even though my "Target, Range" is a different cell, that being
A2 rather than A1.

Is there any way I can have TWO "Worksheet_Change" macros on the same
sheet?

Kaye


On Mon, 19 Feb 2007 19:10:50 -0800, "Doug Glancy"
wrote:

Kaye,

You can use data validation in the cell, with a list of your 13 choices.
Then in that sheet's code module insert a Worksheet_Change Event module.
Assuming your data validated cell is in A1 and your choices are "a", "b"
and
"c" you could use code like this:

Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("A1")) Is Nothing Then
Select Case Range("A1").Value
Case "a"
Call MacroA
Case "b"
Call MacroB
Case "c"
Call MacroC
End Select
End If
End Sub

hth,

Doug

"Kaye" wrote in message
...

Hi - Is it possible to have a dropdown box (listbox/combobox?) of 13
text choices, with each choice assigned to a macro?

Ideally I'd like to run one of 13 macros depending upon what the user
selects from this dropdown box.

My present method is using 13 checkboxes with a different macro
assigned to each - the user ticks it, and my macro fires. This though
is occupies too much screen area.

Any help would be appreciated.




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 55
Default ListBox Selection to fire Macro

Kaye,

Woops. Here you go:

Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("A1")) Is Nothing Then
Select Case Range("A1").Value
Case "a"
Call MacroA
Case "b"
Call MacroB
Case "c"
Call MacroC
End Select
End If
If Not Intersect(Target, Range("A2")) Is Nothing Then
Select Case Range("A2").Value
Case "1"
Call Macro1
Case "2"
Call Macro2
Case "3"
Call Macro3
End Select
End If
End Sub

hth,

Doug

"Kaye" wrote in message
...
Thanks Doug, but I'm having a problem.

Yes, you are correct in your assumption that the validation for A2 is
different.

When I run this new code, from A1 or A2, this is returned:
"Compile Error: Block IF without ENDIF"

The last line of the code, END SUB, is highlighted blue, and
the first line, "Private sub Worksheet_Change etc is highlighted
yellow.

I've transposed your code correctly. Any clues?

Regards, Kaye

On Tue, 20 Feb 2007 16:39:27 -0800, "Doug Glancy"
wrote:

Kaye,

You can't have two Worksheet_Change events, but in your single event you
can
test for each cell separately. Duplicate the code for A2 so that it looks
something like this:

Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("A1")) Is Nothing Then
Select Case Range("A1").Value
Case "a"
Call MacroA
Case "b"
Call MacroB
Case "c"
Call MacroC
End Select
If Not Intersect(Target, Range("A2")) Is Nothing Then
Select Case Range("A2").Value
Case "1"
Call Macro1
Case "2"
Call Macro2
Case "3"
Call Macro3
End Select
End If
End Sub

The above assumes that the validation for A2 is different. But if it's
the
same, just modify it back to the "A" "B" and "C" values.

hth,

Doug

"Kaye" wrote in message
. ..
Thanks for that Doug, that's what I was after!

But - another small problem has come to light ....

I have TWO cells that carry Data Validation list boxes - A1, and also
at A2, just beneath it.

It appears I can't have TWO "Worksheet_Change" macros on the same
sheet, even though my "Target, Range" is a different cell, that being
A2 rather than A1.

Is there any way I can have TWO "Worksheet_Change" macros on the same
sheet?

Kaye


On Mon, 19 Feb 2007 19:10:50 -0800, "Doug Glancy"
wrote:

Kaye,

You can use data validation in the cell, with a list of your 13 choices.
Then in that sheet's code module insert a Worksheet_Change Event module.
Assuming your data validated cell is in A1 and your choices are "a", "b"
and
"c" you could use code like this:

Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("A1")) Is Nothing Then
Select Case Range("A1").Value
Case "a"
Call MacroA
Case "b"
Call MacroB
Case "c"
Call MacroC
End Select
End If
End Sub

hth,

Doug

"Kaye" wrote in message
m...

Hi - Is it possible to have a dropdown box (listbox/combobox?) of 13
text choices, with each choice assigned to a macro?

Ideally I'd like to run one of 13 macros depending upon what the user
selects from this dropdown box.

My present method is using 13 checkboxes with a different macro
assigned to each - the user ticks it, and my macro fires. This though
is occupies too much screen area.

Any help would be appreciated.




  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default ListBox Selection to fire Macro

Thanks so much Doug, it's working great now!

Kaye

On Tue, 20 Feb 2007 19:30:54 -0800, "Doug Glancy"
wrote:

Kaye,

Woops. Here you go:

Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("A1")) Is Nothing Then
Select Case Range("A1").Value
Case "a"
Call MacroA
Case "b"
Call MacroB
Case "c"
Call MacroC
End Select
End If
If Not Intersect(Target, Range("A2")) Is Nothing Then
Select Case Range("A2").Value
Case "1"
Call Macro1
Case "2"
Call Macro2
Case "3"
Call Macro3
End Select
End If
End Sub

hth,

Doug

"Kaye" wrote in message
.. .
Thanks Doug, but I'm having a problem.

Yes, you are correct in your assumption that the validation for A2 is
different.

When I run this new code, from A1 or A2, this is returned:
"Compile Error: Block IF without ENDIF"

The last line of the code, END SUB, is highlighted blue, and
the first line, "Private sub Worksheet_Change etc is highlighted
yellow.

I've transposed your code correctly. Any clues?

Regards, Kaye

On Tue, 20 Feb 2007 16:39:27 -0800, "Doug Glancy"
wrote:

Kaye,

You can't have two Worksheet_Change events, but in your single event you
can
test for each cell separately. Duplicate the code for A2 so that it looks
something like this:

Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("A1")) Is Nothing Then
Select Case Range("A1").Value
Case "a"
Call MacroA
Case "b"
Call MacroB
Case "c"
Call MacroC
End Select
If Not Intersect(Target, Range("A2")) Is Nothing Then
Select Case Range("A2").Value
Case "1"
Call Macro1
Case "2"
Call Macro2
Case "3"
Call Macro3
End Select
End If
End Sub

The above assumes that the validation for A2 is different. But if it's
the
same, just modify it back to the "A" "B" and "C" values.

hth,

Doug

"Kaye" wrote in message
...
Thanks for that Doug, that's what I was after!

But - another small problem has come to light ....

I have TWO cells that carry Data Validation list boxes - A1, and also
at A2, just beneath it.

It appears I can't have TWO "Worksheet_Change" macros on the same
sheet, even though my "Target, Range" is a different cell, that being
A2 rather than A1.

Is there any way I can have TWO "Worksheet_Change" macros on the same
sheet?

Kaye


On Mon, 19 Feb 2007 19:10:50 -0800, "Doug Glancy"
wrote:

Kaye,

You can use data validation in the cell, with a list of your 13 choices.
Then in that sheet's code module insert a Worksheet_Change Event module.
Assuming your data validated cell is in A1 and your choices are "a", "b"
and
"c" you could use code like this:

Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("A1")) Is Nothing Then
Select Case Range("A1").Value
Case "a"
Call MacroA
Case "b"
Call MacroB
Case "c"
Call MacroC
End Select
End If
End Sub

hth,

Doug

"Kaye" wrote in message
om...

Hi - Is it possible to have a dropdown box (listbox/combobox?) of 13
text choices, with each choice assigned to a macro?

Ideally I'd like to run one of 13 macros depending upon what the user
selects from this dropdown box.

My present method is using 13 checkboxes with a different macro
assigned to each - the user ticks it, and my macro fires. This though
is occupies too much screen area.

Any help would be appreciated.


  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default ListBox Selection to fire Macro

Hi
I was looking for help with macros and assigning them to data validation and
saw your posting reply.

What im trying to do is simialr but i have 3 choices in the drop down
validation,
CHOICE A (macro 1)
CHOICE B (macro 2)
CHOICE C (macro 3)

but i need to do this to 9 seperate towns. These are on seperate worksheets
marked as below. the macro that drives the print is the same one but as you
change the worksheet it selects that sheets info.

TOWN 1
TOWN 2
TOWN 3 ETC

I basically select the choice from the data validation dropdown and I want
it to then print using the macro i've set up on the relevant town worksheet

Is this possible to do.

Any help you can offer would be appreciated!



--
MDL2005


"Doug Glancy" wrote:

Kaye,

You can use data validation in the cell, with a list of your 13 choices.
Then in that sheet's code module insert a Worksheet_Change Event module.
Assuming your data validated cell is in A1 and your choices are "a", "b" and
"c" you could use code like this:

Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("A1")) Is Nothing Then
Select Case Range("A1").Value
Case "a"
Call MacroA
Case "b"
Call MacroB
Case "c"
Call MacroC
End Select
End If
End Sub

hth,

Doug

"Kaye" wrote in message
...

Hi - Is it possible to have a dropdown box (listbox/combobox?) of 13
text choices, with each choice assigned to a macro?

Ideally I'd like to run one of 13 macros depending upon what the user
selects from this dropdown box.

My present method is using 13 checkboxes with a different macro
assigned to each - the user ticks it, and my macro fires. This though
is occupies too much screen area.

Any help would be appreciated.

Regards Kaye




Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Fire Macro from Cell Change Slashman Excel Worksheet Functions 7 October 17th 06 04:08 AM
Essbase Causing Selection Change Event to Fire Jim Thomlinson[_5_] Excel Programming 1 December 20th 05 09:39 PM
fire macro on AutoFilter change jeffP Excel Programming 2 September 14th 04 01:12 AM
how to get onkey macro to fire while another macro is running Brian Murphy Excel Programming 8 August 25th 04 05:38 AM
Run a macro when new selection in listbox Georg[_3_] Excel Programming 1 December 5th 03 06:09 PM


All times are GMT +1. The time now is 12:38 AM.

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

About Us

"It's about Microsoft Excel"