View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Nigel Nigel is offline
external usenet poster
 
Posts: 923
Default Move msgbox out of loop

Set another variable to determine the outcome of the loop and use that after
the loop completes... something like.....

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Dim xvalid As Boolean
xvalid = False
For Each cel In Range("FILLIN01")
If IsEmpty(cel) Then xvalid = True
Next cel

If xvalid Then
Ans = MsgBox("Sheet not complete! Would you like to complete
sheet now?", vbYesNo + vbQuestion, "Incomplete Sheet!")
If Ans = vbYes Then
Cancel = True
End If
End If

End Sub

--
Cheers
Nigel



"Phil Floyd" wrote in message
...
Here is the code I am using to check for cells being filled in.

Private Sub Workbook_BeforeClose(Cancel As Boolean)
For Each cel In Range("FILLIN01")
If IsEmpty(cel) Then
Ans = MsgBox("Sheet not complete! Would you like to complete
sheet now?", vbYesNo + vbQuestion, "Incomplete Sheet!")
If Ans = vbYes Then
Cancel = True
End If
End If
Next cel
End Sub

There are several cells in range FILLIN01. If 6 of these are not filled
out, I get the message box 6 times. How do I get the message box only

once
if any of the cells in the range are blank?

Thanks,
Phil