Searching Column and deleting cells -VBA

  • Thread starter Thread starter TLuebke
  • Start date Start date
T

TLuebke

Very new to Excel programming and trying to develop a code snippet I can use
in differant ways. I need to examine the Cells in Column A for the fontstyle
Italics or font size and if it matches the criteria delete them.

This doesn't work:
Dim cells As Object
Dim rng As Range

Set rng = Range("A1:A1000")
For Each cells In rng
If rng.cells.Font.FontStyle = "Italic" Then
rng.cells.Value = ""
End If
Next cells

What would?
 
If you really want to delete the cell/row then loop backwards:

Dim rng As Range
Dim r as Range, i as long

Set rng = Range("A1:A1000")
For i = rng(rng.count).row to rng(1).row step - 1
set r = cells(i,rng.column)
If r.Font.Italic Then
r.entirerow.Delete
End If
Next i

Checking the Italic property of the font is easier than using Font Style.
 
Thanks Tom works like a champ!

Tom Ogilvy said:
If you really want to delete the cell/row then loop backwards:

Dim rng As Range
Dim r as Range, i as long

Set rng = Range("A1:A1000")
For i = rng(rng.count).row to rng(1).row step - 1
set r = cells(i,rng.column)
If r.Font.Italic Then
r.entirerow.Delete
End If
Next i

Checking the Italic property of the font is easier than using Font Style.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top