Combo Array

Molden

Active Member
Joined
Jun 20, 2006
Messages
373
Hi,

Does anyone know how I could clear 3 comboboxes in an array.

For example instead of :

me.combobox1=""
me.combobox2=""
me.combobox3=""

something like:

Dim MyCombo

MyCombo = array(me.combobox1, me.combobox2, me.combobox3)

MyCombo = ""

Thanks
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
Hi,

Where are the comboboxes located? On a sheet? On a userform?

If they are on a sheet, did you add them from the control toolbox or from the forms toolbar?
 
Upvote 0
Hi,

Where are the comboboxes located? On a sheet? On a userform?

If they are on a sheet, did you add them from the control toolbox or from the forms toolbar?

Sorry there on sheet1 and created them from the control toolbox

Thanks
 
Upvote 0
You can use a loop to work through an array or collection:
Code:
Sub foo()
    Dim ole As OLEObject
    
    For Each ole In Me.OLEObjects
        If TypeOf ole.Object Is MSForms.ComboBox Then
            ole.Object.ListIndex = -1
        End If
    Next ole
    
End Sub

Code:
Sub foo2()
    Dim vCombos
    Dim i As Long
    
    vCombos = Array(Me.ComboBox1, Me.ComboBox2, Me.ComboBox3)
    
    For i = LBound(vCombos) To UBound(vCombos)
        vCombos(i).ListIndex = -1
    Next i
    
End Sub
 
Upvote 0
You can use a loop to work through an array or collection:
Code:
Sub foo()
    Dim ole As OLEObject
    
    For Each ole In Me.OLEObjects
        If TypeOf ole.Object Is MSForms.ComboBox Then
            ole.Object.ListIndex = -1
        End If
    Next ole
    
End Sub

Code:
Sub foo2()
    Dim vCombos
    Dim i As Long
    
    vCombos = Array(Me.ComboBox1, Me.ComboBox2, Me.ComboBox3)
    
    For i = LBound(vCombos) To UBound(vCombos)
        vCombos(i).ListIndex = -1
    Next i
    
End Sub


Thanks that worked great
 
Upvote 0

Forum statistics

Threads
1,213,526
Messages
6,114,136
Members
448,551
Latest member
Sienna de Souza

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