ComboBox Query
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 |
ComboBox Query
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 Blobbies wrote: 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 -- Dave Peterson |
ComboBox Query
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 "Dave Peterson" wrote: 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 Blobbies wrote: 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 -- Dave Peterson |
All times are GMT +1. The time now is 05:15 PM. |
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com