J
jacqui
I am using the autofilter method to delete unwanted rows
from my datafile. The autofilter filters the first
criteria, deletes rows and then I repeat the cycle again
using a different criteria value. My code is below and it
works but is there a tidier way of writing it? Can anyone
help?
Many thanks
Jacqui
Sub format_DeleteRows_PersComm()
Dim lLastRow As Long
Dim Rng As Range
Application.ScreenUpdating = False
Rows(1).Insert
Range("F1").Value = "temp"
With ActiveSheet
.UsedRange
lLastRow = .Cells.SpecialCells(xlCellTypeLastCell).Row
Set Rng = Range("F1", Cells(lLastRow, "F"))
Rng.AutoFilter Field:=1, Criteria1:="Pers Total"
Rng.SpecialCells
(xlCellTypeVisible).EntireRow.Delete
.UsedRange
End With
Rows(1).Insert
Range("F1").Value = "temp"
With ActiveSheet
.UsedRange
lLastRow = .Cells.SpecialCells(xlCellTypeLastCell).Row
Set Rng = Range("F1", Cells(lLastRow, "F"))
Rng.AutoFilter Field:=1, Criteria1:="Misc Total"
Rng.SpecialCells
(xlCellTypeVisible).EntireRow.Delete
.UsedRange
End With
Range("F:F").Select
Selection.EntireColumn.Delete
End Sub
from my datafile. The autofilter filters the first
criteria, deletes rows and then I repeat the cycle again
using a different criteria value. My code is below and it
works but is there a tidier way of writing it? Can anyone
help?
Many thanks
Jacqui
Sub format_DeleteRows_PersComm()
Dim lLastRow As Long
Dim Rng As Range
Application.ScreenUpdating = False
Rows(1).Insert
Range("F1").Value = "temp"
With ActiveSheet
.UsedRange
lLastRow = .Cells.SpecialCells(xlCellTypeLastCell).Row
Set Rng = Range("F1", Cells(lLastRow, "F"))
Rng.AutoFilter Field:=1, Criteria1:="Pers Total"
Rng.SpecialCells
(xlCellTypeVisible).EntireRow.Delete
.UsedRange
End With
Rows(1).Insert
Range("F1").Value = "temp"
With ActiveSheet
.UsedRange
lLastRow = .Cells.SpecialCells(xlCellTypeLastCell).Row
Set Rng = Range("F1", Cells(lLastRow, "F"))
Rng.AutoFilter Field:=1, Criteria1:="Misc Total"
Rng.SpecialCells
(xlCellTypeVisible).EntireRow.Delete
.UsedRange
End With
Range("F:F").Select
Selection.EntireColumn.Delete
End Sub