Replacing Colored Cell with a Value in VBA

Schneider

New Member
Joined
Sep 3, 2009
Messages
10
Hello,

I have the following code that looks at column B and replaces all the cells that are zero with blank and then deletes the row between the given range that are blank. My next step would be to select all the colored cells in column B and either delete the row or change the current value to blank. Therefore once blank the row will be deleted.

I am trying unsuccessfully to acheive the next step by the code in red. Does someone know of a code that will do this?

Sheets("Template").Select
Columns("B:B").Replace 0, "", xlWhole
Columns("B:B").Replace Interior.ColorIndex = 3, "", xlWhole
On Error Resume Next
Range("B20:B31").SpecialCells(xlCellTypeBlanks).EntireRow.Delete
ActiveSheet.UsedRange


Thank you.
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
Hi,

To remove the value:

Code:
    lRow = Range("B1").End(xlDown).Row
    For i = 1 To lRow
        If Cells(i, 2).Interior.ColorIndex = 3 Then Cells(i, 2).Value = ""
    Next

To delete the row:

Code:
    lRow = Range("B65536").End(xlUp).Row
    For i = lRow To 1 Step -1
        If Cells(i, 2).Interior.ColorIndex = 6 Then Cells(i, 2).EntireRow.Delete
    Next
 
Upvote 0

Forum statistics

Threads
1,224,617
Messages
6,179,915
Members
452,949
Latest member
beartooth91

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