Deleting rows if one cell in the row is not a specific color

dunk123

Board Regular
Joined
Feb 14, 2008
Messages
77
Hi all

I have a bunch of customer data that is given to sales reps. Each customer account is on one row, with name, address etc in different columns. Using some basic testing principles, any missing or invalid data has its cell colored using:

Code:
With Selection.Interior
                .Color = 65535
            End With

I now wish to loop through all the rows, testing if any cells in the row are colored. If there are no cells in the entire row that are colored, then I wish to delete the row. I've conceptualized how to do it, but just not quite there.

Any help greatly appreciated. Many thanks.
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
Hi. Perhaps like this

Code:
Sub Test2()
Dim LR As Long, LC As Long, i As Long, j As Long, k As Long
LR = Cells.Find(What:="*", SearchDirection:=xlPrevious, SearchOrder:=xlByRows).Row
LC = Cells.Find(What:="*", SearchDirection:=xlPrevious, SearchOrder:=xlByColumns).Column
For i = LR To 1 Step -1
    k = 0
    For j = 1 To LC
        If Cells(i, j).Interior.Color = 65535 Then
            k = 1
            Exit For
        End If
    Next j
    If k = 0 Then Rows(i).Delete
Next i
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,566
Messages
6,179,555
Members
452,928
Latest member
101blockchains

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