Delete Cells with a certain Color or Font

FinancialAnalystKid

Well-known Member
Joined
Oct 14, 2004
Messages
779
I have to make a selection of cells and delete the contents of each cell that has:

Selection.Font.ColorIndex = 6
Selection.Font.Size = 10

Can someone help me with the VBA code for this?

Thanks
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
Is it?

Code:
Dim Cell as Range
For Each cell in Selection
   With Cell
      If .Font.ColorIndex = 6 And .Font.Size = 10 Then .Clear
   End With
Next Cell
 
Upvote 0
Hi,

Try this for a start . . .

Code:
Sub test()

Dim CellRange As Range
Set CellRange = Range("A1:A10")

For Each c In CellRange
    If c.Interior.ColorIndex = 6 And c.Font.Size = 14 Then
    c.Clear
    End If
Next c

End Sub
HTH
Bob
 
Upvote 0
Andrew Poulsom said:
Is it?

Code:
Dim Cell as Range
For Each cell in Selection
   With Cell
      If .Font.ColorIndex = 6 And .Font.Size = 10 Then .Clear
   End With
Next Cell

Thanks! I used ClearContents instead as I needed only the contents versus the color to be cleared.
 
Upvote 0

Forum statistics

Threads
1,203,618
Messages
6,056,320
Members
444,858
Latest member
ucbphd

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