Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 19
Default assign a macro to a combo box

Hi

I'm a fairly new user to Macros

I have a worksheet created in XL2003 that contains five buttons created from
the toolbox. Each button successfully runs its own unique macro basically
hiding and showing specific rows. The Macros are caller Sub Macro1( ) to Sub
Macro5( )

Having just come accross Combo boxes where the source data is allocated a
numerical value ie "One"=1, "Two"=2 etc, I would like to allocate Sub Macro1(
) to "One" and Sub Macro2( ) to "Two" etc. so that I can save a lot of space
in my workbook

How can I do this please

Many thanks
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 5,939
Default assign a macro to a combo box

You can link a cell to your combo box. That cell will then contain the index
of the item selected. Assuming you link to Cell A1 this code should work for
you...

Sub ComboCode()
Select Case Range("A1").Value
Case 1
Call Macro1
Case 2
Call Macro2
Case 3
Call Macro3
Case 4
Call Macro4
Case 5
Call Macro5
End Select
End Sub
--
HTH...

Jim Thomlinson


"dave caizley" wrote:

Hi

I'm a fairly new user to Macros

I have a worksheet created in XL2003 that contains five buttons created from
the toolbox. Each button successfully runs its own unique macro basically
hiding and showing specific rows. The Macros are caller Sub Macro1( ) to Sub
Macro5( )

Having just come accross Combo boxes where the source data is allocated a
numerical value ie "One"=1, "Two"=2 etc, I would like to allocate Sub Macro1(
) to "One" and Sub Macro2( ) to "Two" etc. so that I can save a lot of space
in my workbook

How can I do this please

Many thanks

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 19
Default assign a macro to a combo box

Hi Jim

Thanks for the reply

This takes me part way to where I would like to get to and is workable for
me. I can just create a Run macro button.

However, my ideal solution would be that in having selected 3 from the combo
box drop down, the selection of that choice would run macro3.

Is this possible or am I asking for too much

Thanks

Dave

"Jim Thomlinson" wrote:

You can link a cell to your combo box. That cell will then contain the index
of the item selected. Assuming you link to Cell A1 this code should work for
you...

Sub ComboCode()
Select Case Range("A1").Value
Case 1
Call Macro1
Case 2
Call Macro2
Case 3
Call Macro3
Case 4
Call Macro4
Case 5
Call Macro5
End Select
End Sub
--
HTH...

Jim Thomlinson


"dave caizley" wrote:

Hi

I'm a fairly new user to Macros

I have a worksheet created in XL2003 that contains five buttons created from
the toolbox. Each button successfully runs its own unique macro basically
hiding and showing specific rows. The Macros are caller Sub Macro1( ) to Sub
Macro5( )

Having just come accross Combo boxes where the source data is allocated a
numerical value ie "One"=1, "Two"=2 etc, I would like to allocate Sub Macro1(
) to "One" and Sub Macro2( ) to "Two" etc. so that I can save a lot of space
in my workbook

How can I do this please

Many thanks

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
assign a macro to a combo box dave caizley Excel Discussion (Misc queries) 0 September 19th 07 11:08 AM
Assign F1 as a macro? Ryk Excel Discussion (Misc queries) 7 October 17th 06 01:12 AM
Assign a Macro Pendelfin Excel Discussion (Misc queries) 1 January 10th 06 11:35 PM
How to assign a macro Mike Excel Discussion (Misc queries) 4 July 5th 05 06:43 AM
Un-assign a macro George Gee New Users to Excel 2 December 28th 04 05:44 PM


All times are GMT +1. The time now is 02:15 PM.

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

About Us

"It's about Microsoft Excel"