View Full Version : Solved: Help deleting rows please
Blackie50
05-13-2010, 04:27 AM
I would like to delete entire rows where any cell in column H contains an X on its own.
Can anyone help with the loop as I'm struggling
thanks
Jon
Bob Phillips
05-13-2010, 05:24 AM
DIm LastRow As Long
Application.ScreenUpdating = False
With Activesheet
LastRow = .Cells(.Rows.Count, "H").End(xlUp).Row
For i = LastRow To 2 Step -1
If .Cells(i, "H").Value2 = "X" Then
.Rows(i).Delete
End If
Next i
End With
Application.ScreenUpdating = True
Bob Phillips
05-13-2010, 05:31 AM
Here's another way
Public Sub DeleteRowsUsingAutofilter()
Dim LastRow As Long
Dim rng As Range
Application.ScreenUpdating = False
With ActiveSheet
.Rows(1).Insert
.Range("H1").Value2 = "temp"
LastRow = .Cells(.Rows.Count, "H").End(xlUp).Row
Set rng = .Range("H1").Resize(LastRow)
rng.AutoFilter field:=1, Criteria1:="X"
On Error Resume Next
Set rng = rng.SpecialCells(xlCellTypeVisible)
On Error GoTo 0
If Not rng Is Nothing Then rng.EntireRow.Delete
End With
Application.ScreenUpdating = True
End Sub
Blackie50
05-13-2010, 06:27 AM
Thanks very much - both work OK
regards
Jon
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.