Macro to check for 3 blank cells in a row

Moluccanmom

New Member
Joined
Oct 13, 2016
Messages
41
Hello,
I'm trying to create a macro that goes through different rows (10-20, 25-35....) and checks columns F, G and H to see if at least one cell contains a value (TRUE or FALSE). If all three cells in a row are empty I would like to set the background color of cells A:C to red. If all rows contain values, I would like to display a message box that says: "Everything is complete."
I would appreciate any help to get started!
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
68,031
Office Version
  1. 365
Platform
  1. Windows
If all three cells in a row are empty I would like to set the background color of cells A:C to red
This could be done pretty easily with Conditional Formatting, using a formula like:
=AND(F10="",G10="",H10="")
and choosing the red formatting option.

However, see we need to count this instances anyway and return a message box, it is going to require VBA anyway.
Maybe something like this:
Code:
Sub MyCheckMacro()

    Dim myRange As Range
    Dim cell As Range
    Dim myCount As Long
    
    Application.ScreenUpdating = False
    
'   Set range to be first cell in each row you want to check
    Set myRange = Range("F10:F20,F25:F35,F40:F50")
    
'   Loop through range
    For Each cell In myRange
        If (cell = "") And (cell.Offset(0, 1) = "") And (cell.Offset(0, 2) = "") Then
            Range(cell, cell.Offset(0, 2)).Interior.Color = 255
            myCount = myCount + 1
        End If
    Next cell
    
'   Check to see how many highlights were applied
    If myCount = 0 Then
        MsgBox "Everything is complete"
    End If
            
    Application.ScreenUpdating = True
    
End Sub
You can adjust the range to suit your needs.
 
Upvote 0

Moluccanmom

New Member
Joined
Oct 13, 2016
Messages
41
Thank you for helping me again :)
I have adjusted my range and it works, but can I change the red background color to show up in column A:C instead of F:H?
I tried to move it, but then it changed all cells from A:H to red.
Thanks again!
 
Upvote 0

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
68,031
Office Version
  1. 365
Platform
  1. Windows
Are you still checking F:H for the blanks and then highlighting A:C?
Or are you actually checking and highlighting A:C (and F:H is no longer involved at all)?
 
Upvote 0

Moluccanmom

New Member
Joined
Oct 13, 2016
Messages
41
ADVERTISEMENT
Correct, I check F:H and would like to highlight A:C.
 
Upvote 0

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
68,031
Office Version
  1. 365
Platform
  1. Windows
Change this row:
Code:
Range(cell, cell.Offset(0, 2)).Interior.Color = 255
to:
Code:
Range(cell.Offset(0,-5), cell.Offset(0, -3)).Interior.Color = 255

The key here is that we are looping through column F (so that is the column value of our "cell" variable).
So to get from column F to column A, we need to move 5 columns to the left.
And to get from column F to column C, we need to move 3 columns to the left.
So we use Offset to get there.
 
Upvote 0

Moluccanmom

New Member
Joined
Oct 13, 2016
Messages
41
ADVERTISEMENT
That makes sense :)
I had only changed it to -3 which then highlighted all the cells....
Thank you very much for explaining it too!
 
Upvote 0

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
68,031
Office Version
  1. 365
Platform
  1. Windows
You are welcome!:)
 
Upvote 0

Moluccanmom

New Member
Joined
Oct 13, 2016
Messages
41
I have attached the macro to a button and realized it would be great, if the next time I click it and every row has entries the red color would be cleared.

Problem is, the rows have originally different colors. Maybe I could copy the color from Column D to clear the red? I know it gets really complicated now :(
 
Upvote 0

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
68,031
Office Version
  1. 365
Platform
  1. Windows
If you want to clear all color from your sheet before running the macro, just put this line at the beginning of your code:
Code:
    Cells.Interior.Pattern = xlNone
 
Upvote 0

Forum statistics

Threads
1,195,588
Messages
6,010,607
Members
441,558
Latest member
lambierules

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
Top