Cell validation (IsEmpty) and returning MsgBox

kungfauxn00b

New Member
Joined
Jul 25, 2017
Messages
6
Office Version
  1. 365
Platform
  1. Windows
Hey guys and gals,

I have the following code which checks multiple ranges for blank values and returns a MsgBox for each cell when IsEmpty = TRUE

Code:
Sub Check_Event_Form()

    Dim cell As Range

    For Each cell In Range("D10,D14,D18,D28,D41,D44,D46,D48,D53,D56,D73,AH73")
        If IsEmpty(cell) Then
            MsgBox (cell.Offset(0, -2).Value & " is blank")
        Else
            MsgBox ("All required fields have been entered")
        End If
    Next

End Sub

But, as the the Else MsgBox is included in the For loop, the MsgBox is returned after each check of a cell.

Any suggestions on how I can check all cells and if they all return FALSE, show the all good message? :)

And for a Brucey-bonus, is there any (easy) way I can show all errors in one MsgBox instead after each check?

Huge thanks in advance!

(Please go easy on me, I'm not great with VBA!)
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
How about
Code:
Sub Check_Event_Form()

    Dim Cl As Range
    Dim Msg As String

    For Each Cl In Range("D10,D14,D18,D28,D41,D44,D46,D48,D53,D56,D73,AH73")
        If IsEmpty(Cl) Then Msg = Msg & Cl.Offset(0, -2).Value & " is blank" & vbLf
    Next Cl
    If Len(Msg) = 0 Then Msg = "All required fields have been entered"
    MsgBox Msg

End Sub
I would recommend against using VBA keywords as variables, because it can cause problems (hence I've renamed your cell variable)
 
Last edited:
Upvote 0
Glad to help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,223,705
Messages
6,173,996
Members
452,542
Latest member
Bricklin

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top