How to run macros from combobox selection

B

Benway

Hello.
I've tried everything I can think of using the code below and cannot get
even MsgBox to show according to the selection. If anyone has a working
example, I'd be most appreciative!
Example one:
Private Sub Worksheet_Change(ByVal Target As Range)

Dim Addx As String
Dim Rng As Range

Addx = Target.Validation.Formula1
Set Rng = Range(Right(Addx, Len(Addx) - 1))

If Target.Address = "$A$1" Then
Select Case Target.Value
Case Is = Rng.Cells(1, 1) 'First Drop Down Item
'Call RandD
MsgBox "Macro 01"
Case Is = Rng.Cells(2, 1) 'Second Drop Down Item
'Call MacroB
MsgBox "Macro 02"
Case Is = Rng.Cells(3, 1) 'Third Drop Down Item
'Call MacroC
MsgBox "Macro 03"
End Select
End If

End Sub
============================
Example two:
Sub combo1_Change()
Select Case combo1.Value
Case "This"
MsgBox "This"
Case "That"
MsgBox "That"
Case "The Other Thing"
MsgBox "The Other Thing"
End Select
End Sub
 
B

Benway

:

I would add that example one uses a combo box that is "cell linked" to $A$1,
but Excel doesn't seem to recognize the combo box changing that cell as a
Worksheet change event and nothing happens.


Example two gives me an "object required" error on the first line.
 
R

ryguy7272

Right click the grey-space near one of your toolbars, and select Control
Toolbox. Then add a ComboBox. Right-click the sheet tab and paste this code
into the window that opens:

Private Sub Worksheet_Activate()
ComboBox1.Clear
ComboBox1.AddItem "This"
ComboBox1.AddItem "That"
ComboBox1.AddItem "The Other Thing"
ComboBox1.Text = ComboBox1.List(0)
End Sub
 
B

Benway

Thanks Ryan.
I put the code in, got out of design mode, saved, closed and reloaded the
sheet but the combobox is still empty...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top