構文の制限は実際には2つだけですか?ですから配列を使うか、コードブロックを繰り返すだけですか?エラーは.AutoFilter Field
- Compile error: Named argument not found
のCriteria3:=
にあります。私はちょうどそれが2に限られていることにちょうど驚いている。これの背後にある理由は何ですか?オートフィルタに第3の基準を使用しようとすると、コンパイルエラーが発生しますか?
Sub CleanData()
'B b b b boilerplate!
Dim sht As Worksheet, lastrow As Long, myrange As Range
'Set references up-front
Set sht = ThisWorkbook.Worksheets("MySheet")
'Identify the last row and use that info to set up the Range
With sht
lastrow = .Cells(sht.Rows.Count, "A").End(xlUp).Row
Set myrange = .Range("A2:AS" & lastrow)
End With
Application.DisplayAlerts = False
With myrange
'Apply the Autofilter method to the first column of
.AutoFilter Field:=26, _
Criteria1:="Operator Error", _
Operator:=xlOr, _
Criteria2:="Duplicate", _
Operator:=xlOr, _
Criteria3:="Training/Test"
'ERROR HERE
'Delete the visible rows while keeping the header
On Error Resume Next
.Offset(1, 0).Resize(.Rows.Count - 1).SpecialCells(xlCellTypeVisible).Rows.Delete
On Error GoTo 0
End With
Application.DisplayAlerts = True
'Turn off the AutoFilter
With sht
.AutoFilterMode = False
If .FilterMode = True Then
.ShowAllData
End If
End With
End Sub
なぜない、あなただけの記録マクロそれはコードでそれを行う方法を示す – jsotola
それは間違いなく、フィルタ基準の制限は2です。私はこの不満の限界に一度遭遇し、簡単な選択肢を見つけることができませんでした。この制限を回避するために達成しようとしているものを創造的にする必要があります。 –