View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.misc
Dave Peterson Dave Peterson is offline
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