Hi,
I installed the Excel 2007 on my pc and the following code doesn't work anymore. I have got a debug at the following row:
.Range("H1:H" & .Rows.Count).AutoFilter Field:=1, Criteria1:=myArr(I)
Any suggestions?
Thanks
CODE:
Sub Delete_with_Autofilter_Array1()
Dim Rng As Range
Dim calcmode As Long
Dim myArr As Variant
Dim I As Long
Application.ScreenUpdating = False
Application.DisplayAlerts = False
With Application
calcmode = .Calculation
.Calculation = xlCalculationManual
.ScreenUpdating = False
End With
'Fill in the values that you want to delete
myArr = Array("product1", "product2")
For I = LBound(myArr) To UBound(myArr)
'Sheet with the data, you can also use Sheets("MySheet")
With ActiveSheet
'Firstly, remove the AutoFilter
.AutoFilterMode = False
'Apply the filter
.Range("H1:H" & .Rows.Count).AutoFilter Field:=1, Criteria1:=myArr(I)
Set Rng = Nothing
With .AutoFilter.Range
On Error Resume Next
Set Rng = .Offset(1, 0).Resize(.Rows.Count - 1, 1) _
.SpecialCells(xlCellTypeVisible)
On Error GoTo 0
If Not Rng Is Nothing Then Rng.EntireRow.Delete
End With
'Remove the AutoFilter
.AutoFilterMode = False
End With
Next I
With Application
.ScreenUpdating = True
.Calculation = calcmode
End With
Application.ScreenUpdating = True
Application.DisplayAlerts = True
End Sub
I installed the Excel 2007 on my pc and the following code doesn't work anymore. I have got a debug at the following row:
.Range("H1:H" & .Rows.Count).AutoFilter Field:=1, Criteria1:=myArr(I)
Any suggestions?
Thanks
CODE:
Sub Delete_with_Autofilter_Array1()
Dim Rng As Range
Dim calcmode As Long
Dim myArr As Variant
Dim I As Long
Application.ScreenUpdating = False
Application.DisplayAlerts = False
With Application
calcmode = .Calculation
.Calculation = xlCalculationManual
.ScreenUpdating = False
End With
'Fill in the values that you want to delete
myArr = Array("product1", "product2")
For I = LBound(myArr) To UBound(myArr)
'Sheet with the data, you can also use Sheets("MySheet")
With ActiveSheet
'Firstly, remove the AutoFilter
.AutoFilterMode = False
'Apply the filter
.Range("H1:H" & .Rows.Count).AutoFilter Field:=1, Criteria1:=myArr(I)
Set Rng = Nothing
With .AutoFilter.Range
On Error Resume Next
Set Rng = .Offset(1, 0).Resize(.Rows.Count - 1, 1) _
.SpecialCells(xlCellTypeVisible)
On Error GoTo 0
If Not Rng Is Nothing Then Rng.EntireRow.Delete
End With
'Remove the AutoFilter
.AutoFilterMode = False
End With
Next I
With Application
.ScreenUpdating = True
.Calculation = calcmode
End With
Application.ScreenUpdating = True
Application.DisplayAlerts = True
End Sub