Help with code that deletes rows with certain color

atawil

New Member
Joined
Jun 14, 2011
Messages
10
I am trying to delete a row if a cell in column A is a certain color. I searched all over the internet and found a lot of hits, but none that seem to work, or none that are easy to edit so that I can make them work the way I want (I am still a beginner in VBA).

The most basic and straight forward code I found and editted is pasted below. However, after testing it it doesn't work. I don't get any errors but it doesn't delete any rows. The code is going to be inserted in a big macro that does a lot of other formatting tasks such as deleting and inserting column and rows so I know I have to insert an End if when I get there.

I am using Excel 2010.

Any help is appreciated.

Thanks!


Code:
Sub test()
If Columns("A:A").Interior.Color = RGB(255, 0, 0) Then Rows.Delete
 
End Sub
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
Try

Code:
Sub test()
Dim LR As Long, i As Long
LR = Range("A" & Rows.Count).End(xlUp).Row
For i = LR To 1 Step -1
    If Range("A" & i).Interior.Color = RGB(255, 0, 0) Then Rows(i).Delete
Next i
End Sub
 
Upvote 0
Weaver - The cells are not a result of conditional formatting. They are just cells that are part of a legend for a report that was extracted from some program

Vog - Thanks for replying so quickly! The code works in the test but not in the actual workbook. The rows with the colored cells in the actual work book that I want to delete are out of the normal data range by a couple of rows.
 
Upvote 0
Sorry, Vog your solution worked great! It just didn't work within my original macro or after I ran my orignal macro. My solution for that was to just call it from the beginning of my macro.

Thanks for your help!
 
Upvote 0

Forum statistics

Threads
1,224,548
Messages
6,179,451
Members
452,915
Latest member
hannnahheileen

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