View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.misc
Otto Moehrbach[_2_] Otto Moehrbach[_2_] is offline
external usenet poster
 
Posts: 1,071
Default count array for top three entries and return their number

Rich
If you have multiple rows of such voting, use the following macro. The
results will be put in each row after the vote numbers and those 2 cells
will be colored yellow. HTH Otto
Sub GetBest2() 'If multiple rows
Dim rRngRow As Range, i As Range, Dest As Range
Dim HowMany As Long, What As Long
Dim rColA As Range, j As Range
Set rColA = Range("A1", Range("A" & Rows.Count).End(xlUp))
For Each j In rColA
Set rRngRow = Range(j, Cells(j.Row, Columns.Count).End(xlToLeft))
Set Dest = rRngRow(rRngRow.Count).Offset(, 1)
HowMany = 0
For Each i In rRngRow
If Application.CountIf(rRngRow, i.Value) HowMany Then
HowMany = Application.CountIf(rRngRow, i.Value)
What = i.Value
End If
Next i
Dest = What
Dest.Offset(, 1) = HowMany
Dest.Resize(, 2).Interior.ColorIndex = 6
Next j
End Sub
"Rich DeVito" wrote in message
...
I am trying to solve a scoring problem for a car show.

In a spread sheet we will have entry number of cars running across columns
that represent individual 1st place choices. Without filtering and
resorting
the data (no time at the car show) I need to dynamically determine the top
three entires and return the number of times they show up. I.E if these
are
the car entry numbers in their respective columns.

1 2 1 3 2 4 2 4 1 1 1 4 2

Should return
1 5
2 4
4 3
I don't even need the second number (number of votes, but we probably need
it to verify the formula is working).

Thanks!!