If 3 userform comboboxes are changed, run macro

mafallaize

New Member
Joined
Aug 23, 2011
Messages
31
Hey guys,

I thought this deserved a separate thread after Mike Rickson helped to solve 2 comboboxes changing.

Does anyone know some code which fires a macro if 3 comboboxes have been changed?

Thanks

Mark
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
Here is a proof of concept. Create a new Userform, add three Combo-boxes named ComboBox1, ComboBox2 and ComboBox3, paste the following code and run.

Code:
Option Explicit

Private ComboBox1_IsChanged As Boolean
Private ComboBox2_IsChanged As Boolean
Private ComboBox3_IsChanged As Boolean


Private Sub UserForm_Initialize()
  ComboBox1.List = Array(1, 2, 3)
  ComboBox2.List = Array(4, 5, 6)
  ComboBox3.List = Array(7, 8, 9)
End Sub


Private Sub ComboBox1_Change()
  Call CheckChanges(ComboBox1_IsChanged)
End Sub


Private Sub ComboBox2_Change()
  Call CheckChanges(ComboBox2_IsChanged)
End Sub


Private Sub ComboBox3_Change()
  Call CheckChanges(ComboBox3_IsChanged)
End Sub


Private Sub CheckChanges(ByRef IsChanged As Boolean)
  
  IsChanged = True
  
  If AllChanged Then
    FireMacro
    RevertChanged
  End If
  
End Sub


Private Function AllChanged() As Boolean
  AllChanged = ComboBox1_IsChanged And ComboBox2_IsChanged And ComboBox3_IsChanged
End Function


Private Sub FireMacro()
  MsgBox "MacroFired!" & vbNewLine & vbNewLine & _
    ComboBox1.Value & "~" & ComboBox2.Value & "~" & ComboBox3.Value
End Sub


Private Sub RevertChanged()
  ComboBox1_IsChanged = False
  ComboBox2_IsChanged = False
  ComboBox3_IsChanged = False
End Sub

Hope this helps!
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,337
Members
452,637
Latest member
Ezio2866

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