How to count different names in a column in vba?

0

Good people, I have a question in a work in vba in which, in a column, there are four brands of cars:

And the supposed is to put in cell c15 the mark that we want to look for and in cell d15 it has to appear the number of cars that there are of that mark Thank you

    
asked by anonymous 28.12.2017 / 17:43

1 answer

1

Good morning, you can use the following function that counts the single values:

Public Function CountUnique(rng As Range) As Integer
        Dim dict As Dictionary
        Dim cell As Range
        Set dict = New Dictionary
        For Each cell In rng.Cells
             If Not dict.Exists(cell.Value) Then
                dict.Add cell.Value, 0
            End If
        Next
        CountUnique = dict.Count
    End Function
    
19.02.2018 / 12:39