2017-11-09 17 views
0

私は正しい方向に向いているのか、それとも完全に反対に行くのかはわかりませんが、私はバリアントによってデータをグループ化し、それを数えたいと思います。例えば、VBA Excel、グループ化してカウントする

Dim Fruit As Variant 
Fruit = Array("Apple", "Grape", "Lemon", "Melon", "Orange") 

は、それから私は、すべての一致をカウントし、「フルーツ」にマッチし、何のために列を見つける/検索したいです。 Excelで

は、私は列Dに焦点を当てています

Example

答えて

1

あり、それを行うには、より効率的な方法であるが、これは...働くこと

Sub CountFruit() 

    Dim Fruit As Variant 
    Dim LR As Integer 
    Dim t As Integer 
    Dim g As Integer 

    Fruit = Array("Apple", "Grape", "Lemon", "Melon", "Orange") 

    LR = Cells(Rows.Count, 4).End(xlUp).Row 

    t = 0 

    For x = 2 To LR 
     For g = LBound(Fruit) To UBound(Fruit) 

      If Cells(x, 4).Value = Fruit(g) Then 
       t = t + 1 
      End If 

     Next g 
    Next x 

    NumFruit = t 

End Sub 
関連する問題