2017-10-25 4 views
0

構文の制限は実際には2つだけですか?ですから配列を使うか、コードブロックを繰り返すだけですか?エラーは.AutoFilter Field - Compile error: Named argument not foundCriteria3:=にあります。私はちょうどそれが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 
+0

なぜない、あなただけの記録マクロそれはコードでそれを行う方法を示す – jsotola

+0

それは間違いなく、フィルタ基準の制限は2です。私はこの不満の限界に一度遭遇し、簡単な選択肢を見つけることができませんでした。この制限を回避するために達成しようとしているものを創造的にする必要があります。 –

答えて

1

Criteria3有効なパラメータではありませんが、これを回避するために、あなたは、配列を使用することができます。

(複数の状態のフィルタリング)

Criteria1:=Array("IL", "IN", "MI", "OH", "WV"), Operator:=xlFilterValues 
+0

Aha - 私は良い方法がなければならないことを知っていました。ありがとう – dwirony

関連する問題