Return the row number of a cell if its interior color = 50

R

RyanH

I have a worksheet that I need to delete rows. The first row is always 10,
but the second row can vary past 10. I was wondering if there is quick
function or cleaner way of writing code to find the last row in Col.B that
contains an interior colorindex = 50? This is what I have.

Sub DeleteRows()

' find green line at end of quote sheet
lngLastRow = 10
Do Until Cells(lngLastRow, 2).Interior.ColorIndex = 50
lngLastRow = lngLastRow + 1
Loop

' delete rows (items) from quote sheet
Rows("10:" & lngLastRow).Delete Shift:=xlUp

End Sub
 
W

Wigi

The loop is in principle good.

From Excel 2002 onwards (if I'm not mistaken) you can search on formatting
of a cell with the usual Ctrl-F (you can program that as well in VBA).

Another option is, if the color is set with some logic behind it. Then that
logic could perhaps be used in an autofilter or a regular Find in VBA.
 

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

Top