#1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 410
Default For Each Combobox

Can you use a For each statement in VBA to go through the comboboxes
on a form and tell you how many are filled in? This woudl be easier
then listing them all in the code and doing if statements for each
one.

Thanks,
Jay
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default For Each Combobox

If you named them nicely and knew how many there were, you could use:

dim cCtr as long
for cctr = 1 to 5 '5 comboboxes
with me.controls("combobox" & cctr)
if .listindex < 0 then
msgbox "combobox" & cctr & " is empty"
end if
end with
next cctr

If you didn't know how many there were or they weren't named nicely:

Dim ctrl as control
for each ctrl in me.controls
if typeof ctrl is msforms.combobox then
if ctrl.listindex < 0 then
msgbox ctrl.name & " is empty"
end if
end if
next ctrl


jlclyde wrote:

Can you use a For each statement in VBA to go through the comboboxes
on a form and tell you how many are filled in? This woudl be easier
then listing them all in the code and doing if statements for each
one.

Thanks,
Jay


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 5,939
Default For Each Combobox

You need to traverse through all of the controls and determine which ar combo
boxes something like this...

Dim ctl As Control
Dim lng As Long

For Each ctl In Me.Controls
If TypeOf ctl Is msforms.ComboBox Then lng = lng + 1
Next ctl
MsgBox lng
--
HTH...

Jim Thomlinson


"jlclyde" wrote:

Can you use a For each statement in VBA to go through the comboboxes
on a form and tell you how many are filled in? This woudl be easier
then listing them all in the code and doing if statements for each
one.

Thanks,
Jay

  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 410
Default For Each Combobox

This is what I ended up with. I needed it to count how many had
things in it. I may not have been as clear as I needed to be. Thanks
for your help and Dave's.
Thanks,
Jay

Dim ctl As Control
Dim lng As Long

For Each ctl In Me.Controls
If TypeOf ctl Is msforms.ComboBox Then
If ctl.Value < "" Then lng = lng + 1
End If

Next ctl
MsgBox lng

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 Chris Excel Worksheet Functions 3 June 8th 09 03:22 PM
fill combobox depending on selection from another combobox Adam Francis Excel Discussion (Misc queries) 2 July 24th 08 07:39 PM
combobox into another combobox girlie New Users to Excel 1 September 26th 06 10:31 AM
COMBOBOX smiley New Users to Excel 1 October 12th 05 02:01 PM
Combobox nc Excel Discussion (Misc queries) 1 September 28th 05 02:11 PM


All times are GMT +1. The time now is 03:34 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"