VBA Userform with multiple combobox but same options

becklog

New Member
Joined
Dec 26, 2016
Messages
38
Hi,

I am working on something that requires multiple combobox. Some have unique options but most only require a yes/no option. Is there a way to add that option from combobox10 to combobox 30?

Thank you!
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
Have you considered using option buttons within frames or by setting the GroupName property?

1601593019273.png
 
Upvote 0
Here is an option using a callback.

Create a class module named CommonComboChange. Add the following:
VBA Code:
Option Explicit

Private WithEvents cb As MSForms.ComboBox
Private CallBackParent As Object

Friend Sub Init(caller As Object, o As MSForms.ComboBox)
    Set cb = o
    Set CallBackParent = caller
End Sub

Private Sub cb_Change()
    CallBackParent.MultiComboChange cb
End Sub

Something along these lines in your userform:
VBA Code:
Option Explicit

Private c As New Collection

Private Sub UserForm_Initialize()
    Dim ccc As CommonComboChange, cb As MSForms.ComboBox
    
    For Each cb In Controls
        If Val(Right(cb.Name, 2)) > 9 And Val(Right(cb.Name, 2)) < 31 Then
            Set ccc = New CommonComboChange
            ccc.Init Me, cb
            c.Add ccc
        End If
    Next
End Sub

Public Sub MultiComboChange(cb As MSForms.ComboBox)
    MsgBox "You clicked " & cb.Text & " from " & cb.Name
End Sub
 
Upvote 0

Forum statistics

Threads
1,213,561
Messages
6,114,312
Members
448,564
Latest member
ED38

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