Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Deleting Rows in Excel 2000

Status
Not open for further replies.

graemematthew

Technical User
Jun 10, 2002
6
GB
Is there a way of setting a macro that will look at tall the cells in one column and where it finds a specific value it deletes the whole row.
 
Hi,

This works but it's not very quick.
This will search through all the cells in column A and will delete the entire row where the cell contains ABC

Sub test()
For Each Cell In Range("A:A")
If Cell = "ABC" Then
Cell.EntireRow.Delete
End If
Next
End Sub

 
Sorry ignore previous posting. This won't remove all entries as, as each row is deleted, the cell reference goes out of sync.

Try something like this.

Sub test()
Count = Range("A:A").SpecialCells(xlCellTypeLastCell).Row
Do
If Cells(Count, "A") = "ABC" Then
Rows(Count).EntireRow.Delete
End If
Count = Count - 1
Loop Until Count = 0
End Sub
 
Graeme,

Couldn't leave it as it was as if there is alot of data it could take a while!

As before this will delete all rows where there is ABC in column A.

Sub test()
Set One = Columns("A").Find("ABC", lookat:=xlWhole)
If Not (One) Is Nothing Then
Cells(One.Row, "A").Select
Cells.ColumnDifferences(ActiveCell).EntireRow.Hidden = True
Cells.SpecialCells(xlCellTypeVisible).EntireRow.Delete
Cells.EntireRow.Hidden = False
End If
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top