Need VBA code to delete entire row if cells in Column C are highlighted red

PaigeWarner

New Member
Joined
May 27, 2020
Messages
48
Office Version
  1. 365
Platform
  1. MacOS
I already have conditional formatting in my macro to highlight cells red that meet certain conditions I've assigned but I need VBA coding to add that tells the sheet to delete any row that is highlighted red in column c.
 
VBA Code:
Sub Maybe_A()
Dim i As Long, j As Long, strArr
Application.ScreenUpdating = False
strArr = Array("info", "quote", "hola", "too much")    '<----- Put all the strings in here between double quotation marks
    For i = Cells(Rows.Count, 3).End(xlUp).Row To 2 Step -1
        For j = LBound(strArr) To UBound(strArr)
            If InStr(Cells(i, 3), strArr(j)) <> 0 Then Cells(i, 3).EntireRow.Delete: Exit For
        Next j
    Next i
Application.ScreenUpdating = True
End Sub
 
Upvote 0

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
It is the standard conditional formatting Light Red Fill with Dark Red Text. The fill RGB is 255,199,206.
 
Upvote 0
Light red isn't the standard red try...

VBA Code:
Sub DeleteRed()
    Dim lr As Long, i As Long
    Application.ScreenUpdating = False
    
    lr = Range("C" & Rows.Count).End(xlUp).Row
    
    For i = lr To 2 Step -1
        
        If Cells(i, "C").DisplayFormat.Interior.Color = RGB(255, 199, 206) Then Rows(i).Delete
 
    Next
    
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
I stand corrected
Started in Excel 2010 so my 2007 leaves me in the dark!
 
Upvote 0
That worked, thank you so much for your help!
You're welcome, happy we could help.

You can filter the cells by color, then delete the visible rows.
Thanks for that, always forget that Filter by Color does include Conditional formatting. (y)

VBA Code:
Sub Filterit2()
    Application.ScreenUpdating = False
 
    With Range("C1:C" & Range("C" & Rows.Count).End(xlUp).Row)
 
        .AutoFilter 1, RGB(255, 199, 206), xlFilterCellColor
      
        On Error Resume Next
        .Offset(1).Resize(.Rows.Count - 1).SpecialCells(12).EntireRow.Delete
        On Error GoTo 0
        ActiveSheet.AutoFilterMode = False
 
    End With
 
    Application.ScreenUpdating = True
End Sub
 
Last edited:
Upvote 0
You can filter the cells by color, then delete the visible rows.

Thank you Larry! I actually already had the filter by color in the macro so I just needed a VBA code to recognize Light Red Fill and delete because it would be a different amount of lines cells every time.
 
Upvote 0
Sorry, did not check the message board for a few days.

If you select the coloured call, and pull out the cooler palette, you can find the cell interior color in RGB value, which is a combination of 3 colors.
For example, if you type the following in the VBE's Immediate pane:

range("B2").Interior.Color=rgb(122,180,200)
...or...
columns("C").interior.color=rgb(115,70,136)

You can see that these values actually produce the cell interior color.
Interpolating from this, you can find the RGB values for your coloured cell, then use that in your VBA code to accomplish the task of deleting those cells or rows:

VBA Code:
IF Range("A" & RowNo).Interior.Color=RGB(255,199,206) Then
    'Do whatever you need here
END IF
 
Upvote 0

Forum statistics

Threads
1,214,649
Messages
6,120,732
Members
448,987
Latest member
marion_davis

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