how do i remove unshaded rows from Excel?

G

Guest

i have a large (for me) excel spread sheet. i have about 25 % of the rows
highlighted throughout the sheet. i want to remove all the unhighlighted
rows. how do i do this?
 
S

squenson via OfficeKB.com

Sub RemoveUnhighlightedRows()
' This routine will delete all the rows that have
' no highlighted cells

Dim iFirstRow As Long
Dim iLastRow As Long
Dim i As Long
Dim j As Long
Dim bColoredRow As Boolean


' CHANGE THE TWO LINES BELOW
' TO ADAPT TO YOUR NEEDS
iFirstRow = 1
iLastRow = 1000

Application.ScreenUpdating = False

For i = iLastRow To iFirstRow Step -1
For j = 1 To 256
bColoredRow = False
If Cells(i, j).Interior.Color <> RGB(255, 255, 255) Then
bColoredRow = True
Exit For
End If
Next j
If Not (bColoredRow) Then
Rows(i).Delete
End If
Next i

Application.ScreenUpdating = True

End Sub
 
G

Guest

i must say this looks like it will do the trick, but i don't know what to do
with these lines of code. how and where do i run them? sorry to be living up
to my "name" but i haven't a clue what to do with this.....
 

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