Alter code to show more than 1 blank cell heading in message box

danbates

Active Member
Joined
Oct 8, 2017
Messages
377
Office Version
  1. 2016
Platform
  1. Windows
Hi,

I have the following code I would like altering so if there is more than 1 blank cell in the range it states which ones via the cell headings in the message box.

Code:
Sub IsEmptyRange()Dim cell As Range
Dim bIsEmpty As Boolean


bIsEmpty = False


For Each cell In Range("B7:D7,F7")
    If IsEmpty(cell) = True Then
        'An empty cell was found. Exit loop
        bIsEmpty = True
        Exit For
    End If
Next cell


If bIsEmpty = True Then


    MsgBox "There are empty cells in your range  " & Cells(6, cell.Column).Value


Else
    
    MsgBox "All cells have values!"


End If
End Sub

Thanks

Dan
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
They are just random headings at the moment on row 6

Order = Column B
Password = Column C
Product = Column D
QTY = Column F

Thanks
 
Upvote 0
Hi,

I've managed to get it to work how I would like but I think the code is a little messy.

Code:
Sub MyCellCheck()

    Dim cell As Range
    Dim str As String
    Dim bIsEmpty As Boolean


    
For Each cell In Range("B7:D7,F7")
    If IsEmpty(cell) = True Then
            str = str & Cells(6, cell.Column).Value & vbCrLf
            cell.Interior.Color = RGB(255, 0, 0)
        bIsEmpty = True
        'Exit For
    End If
Next cell
    
    
If bIsEmpty = True Then


    MsgBox str


Else
    
    MsgBox "All cells have values!"
    
    End If
    
[COLOR=#ff0000]For Each cell In Range("B7:D7,F7")
    
    If IsEmpty(cell) = True Then
            str = str & Cells(6, cell.Column).Value & vbCrLf
            cell.Interior.Color = RGB(255, 255, 255)
        bIsEmpty = True
        'Exit For
    End If
  Next cell[/COLOR]
  
End Sub

I am sure there is a easier way so please could someone help me clean the last part of the code (in red) where I have changed the colour of the empty cells from red to white?

Thanks

Dan
 
Upvote 0

Forum statistics

Threads
1,214,376
Messages
6,119,179
Members
448,871
Latest member
hengshankouniuniu

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