2016-04-05 6 views
0

どのようにカウントする& Excelの自動フィルタ条件から値のリストを取得しますか?列 "A"のフィルタオプションを適用した後、チェックボックスで条件を見つけます。条件の数も同様に基準&を取得します。 VBAコードでどうすればいいですか?感謝:)Excelのフィルタオプションから条件と基準を取得

+2

私はこれが**良い質問かもしれないと思っています.........あなたの検索する情報の**具体的な**例であなたの投稿を更新してください。 –

+0

私にとって十分な音です。質問をしていただきありがとうございます。 – user4333011

答えて

1
Sub MatchCount() 
Dim Criteria(1 To n, 1 To 2)            'Define 2 dimensional array to store criteria and its count, change n as per your requirements 
Dim i, j, k As Integer 
For k = 1 To n 
    Criteria(k, 2) = 0 
Next k 
i = 1 
Index = 1 
Do While ActiveSheet.Cells(i, 1) <> 0 
    For j = 1 To n 
     If Criteria(j, 1) = ActiveSheet.Cells(i, 1) Then     'Counts the criteria 
      Criteria(j, 2) = Criteria(j, 2) + 1 
      Exit For 
     End If 
    Next j 
    If j = n+1 Then               'Stores the criteria If it is not found in the array and sets count to one 
     Criteria(Index, 1) = ActiveSheet.Cells(i, 1) 
     Criteria(Index, 2) = Criteria(Index, 2) + 1 
     Index = Index + 1 
    End If 
    i = i + 1 
Loop 
For i = 1 To n               'Print criteria and their respective counts 
    ActiveSheet.Cells(i, 3) = Criteria(i, 1) 
    ActiveSheet.Cells(i, 4) = Criteria(i, 2) 
Next i 
End Sub 
1

それはいくつかのコード、リンクが含まれていると「空気中で私の手を投げる - それをすべてを把握するために年齢を取るために起こっている」と私は半分の答えとしてこれを追加しています。

まず私が停止(私は時間を持っていないとして)製のリンク:今すぐ
http://yoursumbuddy.com/autofilter-vba-operator-parameters/

私がこれまでに書いたコード。その考え方は、表の各列の上にあるセルに式=Filter_Criteria()を入力すると、その列に選択された条件がリストされるという考え方です。私は、事業者は2003年よりも複雑たくさんの地獄あることに気づいたとき、私はうまくいけば、このコードとリンクはあなたに良い出発点を与える

(どのように初心者のための色でフィルタを一覧表示します)
Public Function Filter_Criteria() As String 

    Dim rMe As Range 

    If TypeName(Application.Caller) = "Range" Then 

     'Where's the function being called from. 
     Set rMe = Application.Caller 

     'Is Autofilter on? 
     If rMe.Parent.AutoFilterMode Then 
      With rMe.Parent.AutoFilter 

       'Does the function sit a row above the filtered range? 
       If Not Intersect(rMe.Offset(1), .Range) Is Nothing Then 

        With .Filters(rMe.Column - .Range.Column + 1) 
         If .On Then 

          'Action depending on type of operator. 
          Select Case .Operator 

           'Specific values selected. 
           Case xlFilterValues 


           'Date Filter 
           Case 0 

           'Selected 'Last Month' in date range. 
           Case xlFilterDynamic 

          End Select 
         End If 
        End With 
       End If 
      End With 
     End If 

    End If 

End Function 

を停止しました。 ...あなたが終わりに達するかどうか私たちに知らせてください。

関連する問題