how to enable different macros based on combo box selection?

juju

Board Regular
Joined
Mar 13, 2008
Messages
175
I have a spreadsheet with 2 combo boxes - Combobox 1 enables a user to specify if they want to look at the data on the sheet by week or month - it has just 2 options - "select by week" or "select by month"

The list in combobox 2 changes based on the selection in combobox1 - so if you select "select by week" , a date list by week shows up.

Combobox 2 is supposed to run a macro which updates some backend pivot tables. there are 2 types of backend pivottable - weekly tables and monthly tables.

What i am not sure about is how to get the selections in combobox 2 to run either the weekly macro or the monthly macro based on if combobox1 is set to week or month ...?
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
If its a ComboBox from the Forms menu.

Code:
Select Case ActiveSheet.Shapes("Drop Down 1").ControlFormat.Value
    Case Is = 1
        Call aRoutine
    Case Is = 2
        Call bRoutine
End Select
 
Upvote 0
Thanks for a speedy reply ..

quick clarification:

is it possible to tie in how my drop down list in combo box 2 is generated? So I have a compact code which calls routine a or b and also changes the list in combobox 2 based on whether case is 1 or 2?

I am using offset formulas to define the list ranges in combobox 1 and 2 ...

Thank very much ....
 
Upvote 0
I am geting a compile error with this line:

Code:
Select Case ActiveSheet.Shapes("Drop Down 1").ControlFormat.Value

is it maybe related to the name of the sheet? the drop down box is on a tab called "Data Review". or maybe the name of the combo box? I see DropDown1_Change


If its a ComboBox from the Forms menu.

Code:
Select Case ActiveSheet.Shapes("Drop Down 1").ControlFormat.Value
    Case Is = 1
        Call aRoutine
    Case Is = 2
        Call bRoutine
End Select
 
Upvote 0
The format for getting the value of a Forms combobox is
Code:
MsgBox Workbooks("bookName.xls").Sheets("sheetName").Shapes("controlName").ControlFormat.Value
The workbook, sheet and control names should be adjusted to match your situation.

If you are trying to control the program flow based on two dropdown's entries, something like this should work.

Code:
Dim oneDD as Shape
Dim twoDD as Shape

Set oneDD = Workbooks("bookAleph.xls").Sheets("sheetAlpha").Shapes("Combo1"): Rem adjust
Set twoDD = Workbooks("bookBet.xls").Sheets("sheetBeta").Shapes("Combo2"):Rem adjust

Select Case 100*(oneDD.ControlFormat.Value) + (twoDD.ControlFormat.Value)
    Case Is = 101
        Rem first choice from 1DD, first from 2DD
        Rem some code
    Case Is = 102
        Rem first choice from 1DD, second from 2DD
        Rem some code
    Case Is = 201
        Rem second choice from 1DD, first from 2DD
        Rem some code
    Case Is = 202
        Rem second choice from 1DD, second from 2DD
        Rem some code
'etc.

End Select
 
Upvote 0
The format for getting the value of a Forms combobox is
Code:
MsgBox Workbooks("bookName.xls").Sheets("sheetName").Shapes("controlName").ControlFormat.Value
The workbook, sheet and control names should be adjusted to match your situation.

If you are trying to control the program flow based on two dropdown's entries, something like this should work.

Code:
Dim oneDD as Shape
Dim twoDD as Shape

Set oneDD = Workbooks("bookAleph.xls").Sheets("sheetAlpha").Shapes("Combo1"): Rem adjust
Set twoDD = Workbooks("bookBet.xls").Sheets("sheetBeta").Shapes("Combo2"):Rem adjust

Select Case 100*(oneDD.ControlFormat.Value) + (twoDD.ControlFormat.Value)
    Case Is = 101
        Rem first choice from 1DD, first from 2DD
        Rem some code
    Case Is = 102
        Rem first choice from 1DD, second from 2DD
        Rem some code
    Case Is = 201
        Rem second choice from 1DD, first from 2DD
        Rem some code
    Case Is = 202
        Rem second choice from 1DD, second from 2DD
        Rem some code
'etc.

End Select

Thank you - I am going to test it right now . for the part which says

"Rem first choice from 1DD, second from 2DD
Rem some code"

do i need to put that in literally, or change that to something?
 
Upvote 0
Rem denotes that the line is a comment. (My old school eyes sometimes have trouble seeing an ')

It does not need to be in the code.
 
Upvote 0
I used this but I am getting an "invalid outside procedure" error

Code:
Dim oneDD As Shape
Dim twoDD As Shape

Set oneDD = Workbooks("Dashboard - Draft 4.xls").Sheets("Overview Dashboard").Shapes("Dbase1"): Rem adjust
Set twoDD = Workbooks("Dashboard - Draft 4.xls").Sheets("Overview Dashboard").Shapes("Dbase2"): Rem adjust

Select Case 100 * (oneDD.ControlFormat.Value) + (twoDD.ControlFormat.Value)
    Case Is = 101
        Rem first choice from 1DD, first from 2DD
        Rem some code
    Case Is = 102
        Rem first choice from 1DD, second from 2DD
        Rem some code
    Case Is = 201
        Rem second choice from 1DD, first from 2DD
        Rem some code
    Case Is = 202
        Rem second choice from 1DD, second from 2DD
        Rem some code
'etc.

End Select
 
Upvote 0

Forum statistics

Threads
1,214,854
Messages
6,121,941
Members
449,056
Latest member
denissimo

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top