Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default 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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default 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
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default 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

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Combobox Query Greg[_27_] Excel Programming 3 May 22nd 06 06:15 AM
Combobox query? Greg B[_8_] Excel Programming 2 March 14th 06 12:35 AM
ComboBox Filled by Query DBAL[_6_] Excel Programming 3 May 12th 05 02:22 AM
Combobox query Nigel Excel Discussion (Misc queries) 1 April 29th 05 11:56 AM
Combobox Query Maxime Maugeais Excel Programming 1 November 17th 04 11:36 AM


All times are GMT +1. The time now is 04:46 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"