2016-06-29 7 views
0

私は自分のExcelを見て、値の1つが列から見つかりましたが、それがどのように実行できるか把握できない場合は見つけようとしています。私の目標は、フィルタオプションが存在するかどうかを調べ、それ以外の場合は何もしないことです。誰にでもこれに関するアドバイスをしてください。複数の検索文字列を使用して値が存在するかどうかを調べる

ActiveSheet.Range("$A$1:$N$" & i).AutoFilter Field:=14, Criteria1:=Array(_ 
    "String1", "string2", "string3"), _ 
    Operator:=xlFilterValues 


Set FoundRange = Range("$N$1:$N$" & i).Cells.Find(what:="string1", LookIn:=xlFormulas, lookat:=xlWhole) 

If FoundRange Is Nothing Then 
    Cells.AutoFilter 
    Exit Sub 

Else 
End If 

答えて

0

効果がない場合は、フィルタを適用するだけでフィルタをクリアすることができます。

Sub ClearAutoFilterIfNoEffect() 

    Dim countVisibleRows1 As Long 
    Dim countVisibleRows2 As Long 
    Dim r As Range 

    countVisibleRows1 = WorksheetFunction.Subtotal(103, Range("$A$1:$N$" & i)) 

    Range("$A$1:$N$" & i).AutoFilter Field:=14, Criteria1:=Array("String1", "string2", "string3"), Operator:=xlFilterValues 

    countVisibleRows2 = WorksheetFunction.Subtotal(103, Range("$A$1:$N$" & i)) 

    If countVisibleRows2 = countVisibleRows1 Then 
     If ActiveSheet.AutoFilterMode Then Cells.AutoFilter 
    End If 

End Sub 

そうしないと、各条件

Sub CheckAllConditionsBeforeApplyingFilter() 

    With Range("$A$1:$N$" & i) 
     If .Cells.Find(what:="string1", LookIn:=xlFormulas, lookat:=xlWhole) Is Nothing Then 
      If .Cells.Find(what:="string2", LookIn:=xlFormulas, lookat:=xlWhole) Is Nothing Then 
       If .Cells.Find(what:="string1", LookIn:=xlFormulas, lookat:=xlWhole) Is Nothing Then 
        'Clear the filter if it exists 
        If ActiveSheet.AutoFilterMode Then Cells.AutoFilter 
        Exit Sub 
       Else 

        .AutoFilter Field:=14, Criteria1:=Array("String1", "string2", "string3"), Operator:=xlFilterValues 

       End If 
      End If 
     End If 
    End With 
End Sub 
+0

私は助けることができるとうれしいをチェックする必要があります! –

関連する問題