ComboBox Query

  • Thread starter Thread starter Blobbies
  • Start date Start date
B

Blobbies

I have a number of comboboxes on a userform.

They share a common prefix in their name and are then numbered i.e. cbx1,
cbx2, cbx3 etc.

I want to run a For .... Next procedure with these comboboxes, and am
wondering how to refer to them within this procedure - i.e "cbx" & (whatever
number - starting at 1 through to 10)

Is this possible?

Thanking you in advance!



Edi
 
Option Explicit
Private Sub CommandButton1_Click()
Dim ctrl As Control
Dim iCtr As Long
For iCtr = 1 To 10
Set ctrl = Me.Controls("cbx" & iCtr)
'do what you want???
'clear the combobox
ctrl.ListIndex = -1
Next iCtr
End Sub

You could also loop through the controls and work on just the comboboxes.

Option Explicit
Private Sub CommandButton1_Click()
Dim ctrl As Control
For each ctrl in me.controls
if typeof ctrl is msforms.combobox then
ctrl.listindex = -1
end if
next ctrl
End Sub
 
Thank you Dave!! I was close in my trial and error attempts, but I'm not
sure whether I would have got there in the end or not!!!



Edi
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top