【发布时间】:2015-10-26 21:48:04
【问题描述】:
所以过去几天我一直在研究这个问题,但我似乎无法让它发挥作用。
Sub Button3_Click()
Dim DeleteValue As String
Dim rng As Range
Dim calcmode As Long
With Application
calcmode = .Calculation
.Calculation = xlCalculationManual
.ScreenUpdating = False
End With
'Fill in the value that you want to delete
'Tip: use DeleteValue = "<>ron" to delete rows without ron
DeleteValue = "<>assap"
'Sheet with the data, you can also use Sheets("MySheet")
With ActiveSheet
'Firstly, remove the AutoFilter
ActiveSheet.AutoFilterMode = False
'Apply the filter 'The problem is this line according to the debugger
ActiveSheet.Sheets("Sheet1").Range("A2:A" & .Rows.Count).AutoFilter Field:=1, Criteria1:=DeleteValue
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
With Application
.ScreenUpdating = True
.Calculation = calcmode
End With
End Sub
这应该做的是在 A 列中查找没有“assap”的单元格并删除它们,但我不确定这段代码有什么问题,我确实在网上找到了它,大多数人似乎都有它工作,但我。我也尝试添加并尝试其他事情,但仍然会发生同样的问题,如果有人可以帮助我,我将不胜感激。
错误是438运行时错误
【问题讨论】:
-
你为什么在第二行开始你的过滤器?过滤器应(即必须)包含标题行。数据从哪一行开始?第 2 行还是第 3 行?
-
因为数据从第二行开始