Thread: For Each / Next
View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 6,953
Default For Each / Next

I checked all sheets because the sample code you posted appeared to be doing
that. Certainly you can just set the variable Sh to refer to a single sheet
and remove that outer loop.

Dim sh as Worksheet, obj as OleObject
Dim msg as Variant
set sh = worksheets("Sheet1")
for each obj in sh.OleObjects
if typeof obj.Object is MSForms.Combobox then
if obj.Object.Value = "" then
Msg = MsgBox("All questions have not been completed. " & _
" Please double-check the drop down boxes to ensure no " & _
"questions were left unanswered.", vbOKOnly, "Missing Answers")
exit sub
end if
end if
Next

--
Regards,
Tom Ogilvy


"NicB." wrote:


Thank you, Tom. The combo-boxes are controls, not forms. Your code
worked very well, with the exception of one minor detail. The code
checks all sheets in the workbook, what if I needed it to only
reference one sheet? Is there a way to specify the worksheet? I will
try to solve this, but if you have the answer, I would greatly
appreciate it.

Thanks again for your help!

NicB.


--
NicB.
------------------------------------------------------------------------
NicB.'s Profile: http://www.excelforum.com/member.php...o&userid=20639
View this thread: http://www.excelforum.com/showthread...hreadid=544297