View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.misc
Dave Peterson
 
Posts: n/a
Default Userform combo box triggering macros

I put these in a general module:
Option Explicit
Sub MakeMan1()
MsgBox "hi from 1"
End Sub
Sub MakeMan2()
MsgBox "hi from 2"
End Sub
Sub MakeMan3()
MsgBox "hi from 3"
End Sub
Sub MakeMan4()
MsgBox "hi from 4"
End Sub
Sub MakeMan5()
MsgBox "hi from 5"
End Sub
Sub MakeMan6()
MsgBox "hi from 6"
End Sub
Sub MakeMan7()
MsgBox "hi from 7"
End Sub
Sub MakeMan8()
MsgBox "hi from 8"
End Sub
Sub MakeMan9()
MsgBox "hi from 9"
End Sub
Sub MakeMan10()
MsgBox "hi from 10"
End Sub

I put this behind the userform:

Option Explicit
Private Sub ComboBox1_Change()
If Me.ComboBox1.ListIndex < 0 Then
Exit Sub
Else
Application.Run "MakeMan" & Me.ComboBox1.ListIndex + 1
End If
End Sub
Private Sub UserForm_Initialize()
Dim iCtr As Long
For iCtr = 1 To 10
Me.ComboBox1.AddItem iCtr
Next iCtr
End Sub


And it worked ok for me.

Just a thought...

As a user, I often screw up and choose the wrong item from a
listbox/combobox/checkbox/optionbutton, well every control there is! I think
I'd want to see an Ok button that does the real work--instead of using the
_click event.

But that's just me...

michaelberrier wrote:

I'm using a UserForm with a Combo Box that displays the numbers 1-10 as
choices. I need a different macro to fire based on whatever number is
selected. I've tried many of the solutions offered by previous posts,
but I can't make it work. i.e.: Should the user select "1", then the
macro "makeman1" will execute and so forth through "10".

Thanks in advance. Please be specific in any reply about how the
syntax should be.


--

Dave Peterson