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.
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
You'll have to use the underlying rule that made the cells red.
In other words, use the condition you used for CF.
 
Upvote 0
Here is some of the code for one of the conditions I set. What are you suggesting I use out of this?

Columns("C:C").Select
Selection.FormatConditions.Add Type:=xlTextString, String:="info", _
TextOperator:=xlContains
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Font
.Color = -16383844
.TintAndShade = 0
End With
With Selection.FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.Color = 13551615
.TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = False


Thanks in advance for any assistance you can provide!
 
Upvote 0
I never use conditional formatting. All Greek to me but if I read it right what you want is that if the string in the cell in question in Column C contains the word "info", you want a color applied to that cell.
Is that right?
So what you would like is that if a cell in Column C contains "info" somewhere in the string, you would like the whole Row deleted. Did I understand that right?
 
Upvote 0
This is just an example of one of the (many) conditions I set. I had tons of cells highlighted red in column c, if there are certain words in those cells. Now I want to go a step further and instead of having to manually delete all the rows with cells highlighted red in column c, I am hoping to find code that can do it. Code that will look in column c for any cells highlighted red and then delete the whole row. Does that make sense?
 
Upvote 0
Maybe the code below (test on a copy of your sheet as you are deleting) for your condition as you had it, you can check for the cell colour but it will be slower code as you have to loop though each cell (and not sure if it works on a MAC)..

VBA Code:
Sub Filterit()
    Application.ScreenUpdating = False
  
    With Range("C1:C" & Range("C" & Rows.Count).End(xlUp).Row)
  
        .AutoFilter 1, "*info*"
      
        On Error Resume Next
        .Offset(1).Resize(.Rows.Count - 1).SpecialCells(12).EntireRow.Delete
        On Error GoTo 0
        .AutoFilter
  
    End With
  
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
If you do want to test if deleting based on the colour red does work on a MAC try the code below. Please note that the red must be the standard red.

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.ColorIndex = 3 Then Rows(i).Delete
 
    Next
    
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
I get a run-time error and in the Debug it highlights at the AutoFilter line.
 

Attachments

  • Screen Shot 2020-05-28 at 6.35.38 PM.png
    Screen Shot 2020-05-28 at 6.35.38 PM.png
    34.1 KB · Views: 8
Upvote 0
In the second code, it does nothing to my sheet unfortunately. Appreciate your help regardless, thank you!
 
Upvote 0
In the second code, it does nothing to my sheet unfortunately. Appreciate your help regardless, thank you!

Click one of the red cells, right click, format cells, fill, more colors, custom. There will be 3 numbers are they 255, 0, 0 ?

As for the first code I have no idea why you are getting the error there as I don't get one. What does the error message state?
 
Upvote 0

Forum statistics

Threads
1,215,062
Messages
6,122,923
Members
449,094
Latest member
teemeren

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