Assume I have an array that has the following data:
apples
apples
apples
apples
oranges
grapes
oranges
apples
oranges
grapes
bananas
How can I make the output look like this:
Item count
apples 5
oranges 3
grapes 2
bananas 1
I am not looking for a pivot table solution, but rather a code in VBA.
Thanks in advance for all your help.
Current Code I am using the following:
'Setting Up Dynamic Array to Store Fruit Selections
Dim MyArray() As Variant
'Counting # of Rows
Dim lRow As Long
lRow = ws.Range("A13", ws.Range("A13").End(xlDown)).Rows.Count
'Resize Array
ReDim MyArray(lRow)
For i = 1 To lRow
MyArray(x) = ws.Cells(i + 12, 11)
x = x + 1
Next
Now that I have stored all the fruit values in the array, how can I count the number of unique fruits and their respective count?
Dim MyArray As Variantand thenMyArray = Application.WorksheetFunction.Transpose(ws.Range("A13", ws.Range("A13").End(xlDown)).Value)would get you a single-dimensional array with all the values, without needing a loop and without needing to read each individual cell values - assuminglRow > 13.