Posted to microsoft.public.excel.programming
|
|
Delete row by color of font
That worked perfectly. I'd really like to understand the code. Would you
mind explaining why it works? Is UserResponse a special type of object?
Regards,
Lee
"Rick Rothstein" wrote:
Same code, different color property...
Sub DeleteRedFontRows()
Dim UserResponse As Variant
On Error GoTo NoRedFonts
Application.ScreenUpdating = False
Application.FindFormat.Font.Color = vbRed
Do
Columns("A").Find("*", SearchFormat:=True).EntireRow.Delete
Loop
NoRedFonts:
Application.ScreenUpdating = True
End Sub
Note the I used the VB built in constant vbRed instead of using an RGB
function call to produce the same value.
--
Rick (MVP - Excel)
"Lee" wrote in message
...
Hmmm, that didn't work for me. Perhaps the problem is that I have a
different color of Red than ColorIndex 3. This works:
Sub DeleteRowsWithRedFont()
Dim row As Integer
For i = 2 To 81
If Range(Cells(i, 1), Cells(i, 1)).Font.Color = RGB(255, 0, 0) Then
Rows(i).Delete shift:=xlUp
End If
Next
End Sub
However, I like your method better since there is less looping. Do you
know
how to relate RGB to ColorIndex colors?
Regards,
Lee
"Lee" wrote:
I have 80 rows of data and and one of the columns contains the serial
number
of the row (i.e. 1 through 80). The serial number font is normally black
but
if the font is red, I need to find the row number to delete that row.
Does
anyone know how to do that? It would be nice to do it without looping to
save time.
Thanks in advance,
|