Msgbox to list empty cells on worksheet

loss1003

Board Regular
Joined
Jul 2, 2008
Messages
100
How do I create a code to notify the user the following cells are empty on sheet1. Prior to printing I want a msgbox to come up listing the cells that are empty. Any help is appreciated.

Sheet1.Range("B3").text
Sheet1.Range("B10").text
Sheet1.Range("B11").text
Sheet1.Range("D10").text
Sheet1.Range("D11").text
Sheet1.Range("B50").text
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Try...

Code:
[font=Verdana][color=darkblue]Option[/color] [color=darkblue]Explicit[/color]

[color=darkblue]Sub[/color] test()

    [color=darkblue]Dim[/color] MyRefs [color=darkblue]As[/color] [color=darkblue]Variant[/color]
    [color=darkblue]Dim[/color] Ref [color=darkblue]As[/color] [color=darkblue]Variant[/color]
    [color=darkblue]Dim[/color] Msg [color=darkblue]As[/color] [color=darkblue]String[/color]

    MyRefs = Array("B3", "B10", "B11", "D10", "D11", "B50")
    
    [color=darkblue]For[/color] [color=darkblue]Each[/color] Ref [color=darkblue]In[/color] MyRefs
        [color=darkblue]With[/color] Sheet1
            [color=darkblue]If[/color] .Range(Ref).Text = "" [color=darkblue]Then[/color]
                Msg = Msg & Ref & vbNewLine
            [color=darkblue]End[/color] [color=darkblue]If[/color]
        [color=darkblue]End[/color] [color=darkblue]With[/color]
    [color=darkblue]Next[/color] Ref
    
    [color=darkblue]If[/color] Msg <> "" [color=darkblue]Then[/color]
        MsgBox "The folloiwng cells are empty..." & vbNewLine & vbNewLine & Msg, vbInformation
    [color=darkblue]Else[/color]
        MsgBox "No empty cells found...", vbInformation
    [color=darkblue]End[/color] [color=darkblue]If[/color]
    
[color=darkblue]End[/color] [color=darkblue]Sub[/color]
[/font]
 
Upvote 0
A different option:
Code:
Sub check_cells()
numEmptyCells = 0
Msg = ""
If Sheets(1).Range("B3").Value = "" Then
    numEmptyCells = numEmptyCells + 1
    Msg = Msg & vbCrLf & "B3"
End If
If Sheets(1).Range("B10").Value = "" Then
    numEmptyCells = numEmptyCells + 1
    Msg = Msg & vbCrLf & "B10"
End If
If Sheets(1).Range("B11").Value = "" Then
    numEmptyCells = numEmptyCells + 1
    Msg = Msg & vbCrLf & "B11"
End If
If Sheets(1).Range("D10").Value = "" Then
    numEmptyCells = numEmptyCells + 1
    Msg = Msg & vbCrLf & "D10"
End If
If Sheets(1).Range("D11").Value = "" Then
    numEmptyCells = numEmptyCells + 1
    Msg = Msg & vbCrLf & "D11"
End If
If Sheets(1).Range("B50").Value = "" Then
    numEmptyCells = numEmptyCells + 1
    Msg = Msg & vbCrLf & "B50"
End If
If numEmptyCells > 0 Then
    MsgBox "Please fill the following " & numEmptyCells & " cells:" & Msg, vbExclamation
Else
    MsgBox "Go ahead and print", vbInformation
End If
End Sub
 
Upvote 0
Thanks works great..

Can we add the following msg to the msg box for empty cells in column C but only if Column B = Yes and Column C = "" (empty)..

B C
<TABLE style="WIDTH: 513pt; BORDER-COLLAPSE: collapse" cellSpacing=0 cellPadding=0 width=685 border=0 x:str><COLGROUP><COL style="WIDTH: 206pt; mso-width-source: userset; mso-width-alt: 10057" width=275><COL style="WIDTH: 119pt; mso-width-source: userset; mso-width-alt: 5814" width=159><COL style="WIDTH: 188pt; mso-width-source: userset; mso-width-alt: 9179" width=251><TBODY><TR style="HEIGHT: 15.75pt" height=21><TD class=xl24 style="BORDER-RIGHT: windowtext 0.5pt solid; BORDER-TOP: windowtext 0.5pt solid; BORDER-LEFT: windowtext 0.5pt solid; WIDTH: 206pt; BORDER-BOTTOM: windowtext 0.5pt solid; HEIGHT: 15.75pt; BACKGROUND-COLOR: #ccffff" width=275 height=21>Yes</TD><TD class=xl24 style="BORDER-RIGHT: windowtext 0.5pt solid; BORDER-TOP: windowtext 0.5pt solid; BORDER-LEFT: windowtext; WIDTH: 307pt; BORDER-BOTTOM: windowtext 0.5pt solid; BACKGROUND-COLOR: #ccffff" width=410 colSpan=2> </TD></TR><TR style="HEIGHT: 15.75pt" height=21><TD class=xl24 style="BORDER-RIGHT: windowtext 0.5pt solid; BORDER-TOP: windowtext; BORDER-LEFT: windowtext 0.5pt solid; BORDER-BOTTOM: windowtext 0.5pt solid; HEIGHT: 15.75pt; BACKGROUND-COLOR: #ccffff" height=21>Yes</TD><TD class=xl24 style="BORDER-RIGHT: windowtext 0.5pt solid; BORDER-TOP: windowtext 0.5pt solid; BORDER-LEFT: windowtext; BORDER-BOTTOM: windowtext 0.5pt solid; BACKGROUND-COLOR: #ccffff" colSpan=2> </TD></TR><TR style="HEIGHT: 15.75pt" height=21><TD class=xl24 style="BORDER-RIGHT: windowtext 0.5pt solid; BORDER-TOP: windowtext; BORDER-LEFT: windowtext 0.5pt solid; BORDER-BOTTOM: windowtext 0.5pt solid; HEIGHT: 15.75pt; BACKGROUND-COLOR: #ccffff" height=21>Yes</TD><TD class=xl24 style="BORDER-RIGHT: windowtext 0.5pt solid; BORDER-TOP: windowtext 0.5pt solid; BORDER-LEFT: windowtext; BORDER-BOTTOM: windowtext 0.5pt solid; BACKGROUND-COLOR: #ccffff" colSpan=2> </TD></TR></TBODY></TABLE>

B41:C44
 
Upvote 0
I don't really understand what message you want to give, but you can play with the if-statements:

Code:
If Sheets(1).Range("B41").Value = "Yes" And  Sheets(1).Range("C41").Value = "" Then
    numEmptyCells = numEmptyCells + 1
    Msg = Msg & vbCrLf & "C41"
End If
 
Upvote 0
Thanks works great..

Can we add the following msg to the msg box for empty cells in column C but only if Column B = Yes and Column C = "" (empty)..

B C
<TABLE style="WIDTH: 513pt; BORDER-COLLAPSE: collapse" cellSpacing=0 cellPadding=0 width=685 border=0 x:str><COLGROUP><COL style="WIDTH: 206pt; mso-width-source: userset; mso-width-alt: 10057" width=275><COL style="WIDTH: 119pt; mso-width-source: userset; mso-width-alt: 5814" width=159><COL style="WIDTH: 188pt; mso-width-source: userset; mso-width-alt: 9179" width=251><TBODY><TR style="HEIGHT: 15.75pt" height=21><TD class=xl24 style="BORDER-RIGHT: windowtext 0.5pt solid; BORDER-TOP: windowtext 0.5pt solid; BORDER-LEFT: windowtext 0.5pt solid; WIDTH: 206pt; BORDER-BOTTOM: windowtext 0.5pt solid; HEIGHT: 15.75pt; BACKGROUND-COLOR: #ccffff" width=275 height=21>Yes</TD><TD class=xl24 style="BORDER-RIGHT: windowtext 0.5pt solid; BORDER-TOP: windowtext 0.5pt solid; BORDER-LEFT: windowtext; WIDTH: 307pt; BORDER-BOTTOM: windowtext 0.5pt solid; BACKGROUND-COLOR: #ccffff" width=410 colSpan=2> </TD></TR><TR style="HEIGHT: 15.75pt" height=21><TD class=xl24 style="BORDER-RIGHT: windowtext 0.5pt solid; BORDER-TOP: windowtext; BORDER-LEFT: windowtext 0.5pt solid; BORDER-BOTTOM: windowtext 0.5pt solid; HEIGHT: 15.75pt; BACKGROUND-COLOR: #ccffff" height=21>Yes</TD><TD class=xl24 style="BORDER-RIGHT: windowtext 0.5pt solid; BORDER-TOP: windowtext 0.5pt solid; BORDER-LEFT: windowtext; BORDER-BOTTOM: windowtext 0.5pt solid; BACKGROUND-COLOR: #ccffff" colSpan=2> </TD></TR><TR style="HEIGHT: 15.75pt" height=21><TD class=xl24 style="BORDER-RIGHT: windowtext 0.5pt solid; BORDER-TOP: windowtext; BORDER-LEFT: windowtext 0.5pt solid; BORDER-BOTTOM: windowtext 0.5pt solid; HEIGHT: 15.75pt; BACKGROUND-COLOR: #ccffff" height=21>Yes</TD><TD class=xl24 style="BORDER-RIGHT: windowtext 0.5pt solid; BORDER-TOP: windowtext 0.5pt solid; BORDER-LEFT: windowtext; BORDER-BOTTOM: windowtext 0.5pt solid; BACKGROUND-COLOR: #ccffff" colSpan=2> </TD></TR></TBODY></TABLE>

B41:C44

Is this what you mean?

Code:
[font=Verdana][color=darkblue]Option[/color] [color=darkblue]Explicit[/color]

[color=darkblue]Sub[/color] test()

    [color=darkblue]Dim[/color] Rng [color=darkblue]As[/color] Range
    [color=darkblue]Dim[/color] Cell [color=darkblue]As[/color] Range
    [color=darkblue]Dim[/color] Msg [color=darkblue]As[/color] [color=darkblue]String[/color]
    
    [color=darkblue]Set[/color] Rng = Sheet1.Range("B41:B44")

    [color=darkblue]For[/color] [color=darkblue]Each[/color] Cell [color=darkblue]In[/color] Rng
        [color=darkblue]If[/color] UCase(Cell.Value) = "YES" And Cell(1, 2).Value = "" [color=darkblue]Then[/color]
            Msg = Msg & Cell(1, 2).Address(False, False) & vbNewLine
        [color=darkblue]End[/color] [color=darkblue]If[/color]
    [color=darkblue]Next[/color] Cell
    
    [color=darkblue]If[/color] Msg <> "" [color=darkblue]Then[/color]
        MsgBox "The folloiwng cells are empty..." & vbNewLine & vbNewLine & Msg, vbInformation
    [color=darkblue]Else[/color]
        MsgBox "No empty cells found...", vbInformation
    [color=darkblue]End[/color] [color=darkblue]If[/color]
    
[color=darkblue]End[/color] [color=darkblue]Sub[/color]
[/font]
 
Upvote 0

Forum statistics

Threads
1,224,587
Messages
6,179,735
Members
452,939
Latest member
WCrawford

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