View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Patrick Molloy[_2_] Patrick Molloy[_2_] is offline
external usenet poster
 
Posts: 1,298
Default Having A Macro Run When A Selection Is Made

if your months are in order, then JAn is index 0 and Dec is inex 11
if your macros are also similarly numerically assigned, then

Private Sub ComboBox1_Change()
If ComboBox1.ListIndex = -1 Then Exit Sub
Run "macro" & ComboBox1.ListIndex + 1
End Sub



"bgkgmg" wrote:

I have a combobox on a userform with a drop down list consisting of the 12
months. When I select a month I want the corresponding macro to run.
Example-After selecting January macro4 will run:
Sub Macro4()
ActiveSheet.Unprotect
Application.Goto Reference:="PAYMENTS!R1C16:R1C32"
ActiveSheet.Protect
End Sub

Private Sub cbomonth_Change()
If cbomonth.Value = "January" Then Macro4

I am having trouble in what to add above when I select February(Macro3)
Sub Macro3()
ActiveSheet.Unprotect
Application.Goto Reference:="PAYMENTS!R1C35:R1C51"
ActiveSheet.Protect
End Sub
which I want to bring me to
Application.Goto Reference:="PAYMENTS!R1C35:R1C51"

Thanks