• Status: Solved
• Priority: Medium
• Security: Public
• Views: 330

# Delete Unhighlighted rows

I have a spreadsheet with over 15,000 rows

I am looking for a macro that will delete any row that is unhighlighted.

Thanks
0
zyanj
• 5
• 3
1 Solution

EngineerCommented:
How do you highlight/unhighlight a row. Can you upload a sample sheet?
0

Commented:
Try this:

sub delete()

dim x as integer
x = 1
do until cells(x,1).value = ""
if cells(x,1).Interior.Pattern = xlNone then rows(x).delete
x = x + 1
loop

end sub
0

Commented:
(My code tests column A for in each row to check if it is highlighted)
0

Author Commented:
etech0,sorry, the macro did not work

attached is my sheet minus my data, thanks Book1.xlsx
0

Commented:
Sorry. Try this, where 15000 is the last possible row that needs to be processed.

Sub delete()

Dim x As Integer
x = 1
Do Until x = 15000
If Cells(x, 1).Interior.Pattern = xlNone Then Rows(x).delete
x = x + 1
Loop

End Sub
0

Author Commented:
did not delete all cell there were several hundred gaps
0

Commented:
Try this:

Sub delete()

Dim x As Integer
x = 1
Do Until x = 15000
If Cells(x, 1).Interior.Pattern = xlNone Then
Rows(x).delete
Else
x = x + 1
End If
Loop

End Sub
0

Author Commented:
perfection
0

Commented: