Color index

anilg0001

Rules Violation
Joined
Jun 7, 2010
Messages
193
I want to delete the value of a cell if its colorindex = yellow

i wrote this code
but some where its shows error.

Option Explicit
Sub YelloDelete()
Dim M As Long
Range("A1").Select
M = Sheets("Sheet1").Range("A" & Rows.Count).End(xlUp).Row
For M = M To 1 Step -1
With Range("A" & M)
.ColorIndex = 6
.cell.Value = ""
End With
Next M
End Sub

I want to delete the value from A range to E range if its back ground color is yellow?
understand the question?
 

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.
Try

Code:
Sub YellowDelete()
Dim LR As Long, i As Long, j As Long
LR = Cells(Rows.Count, 1).End(xlUp).Row
For i = 1 To LR
    For j = 1 To 5
        With Cells(i, j)
            If .Interior.ColorIndex = 6 Then .Clear
        End With
    Next j
Next i
End Sub
 
Upvote 0
thanks
i have some more doubts

if my B range or E range have the value as 'rental' then i want to delete
A,B and D,E
suppose
if b15 contain rental then i want to delete the value of a15 and b15
if E23 contain rental then i want to delete the value of D23 and E23

'rental' only shows at B range or E range
 
Last edited:
Upvote 0
Try

Code:
Sub YellowDelete()
Dim LR As Long, i As Long, j As Long
LR = Cells(Rows.Count, 1).End(xlUp).Row
For i = 1 To LR
    For j = 1 To 5
        With Cells(i, j)
            If .Interior.ColorIndex = 6 Then .Clear
            If (j = 2 Or j = 5) And LCase(.Value) Like "*rental*" Then .Offset(, -1).Resize(, 2).Clear
        End With
    Next j
Next i
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,531
Messages
6,179,380
Members
452,907
Latest member
Roland Deschain

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