Based on the idea of this thread
i expanded the idea from a fixed 3 elements to any number of elements, now i want to count their total appearances as max but with one caveat, if we have more than 1 max in the row then the count of each element want to be counted / the number of max, as per the image below
I created an array with all the matched max and then i created this code to do it for 3 elements which works fine but it is obviously a very dumb way of doing it.
Thanks again for the wisdom you are sharing.
Index Max the xth element to VBA
Hello i have the following problem In the first row i have a list of elements and at subsequent rows random numbers under each element and i want to match the element with the max of each row, all the max values though not just the first one. This is achieved by the following function...
www.mrexcel.com
i expanded the idea from a fixed 3 elements to any number of elements, now i want to count their total appearances as max but with one caveat, if we have more than 1 max in the row then the count of each element want to be counted / the number of max, as per the image below
I created an array with all the matched max and then i created this code to do it for 3 elements which works fine but it is obviously a very dumb way of doing it.
VBA Code:
Dim CA as Double
Dim CB as Double
Dim CC as Double
CA=0
CB=0
CC=0
For i = 1 To UBound(arrcount)
For j = 2 To 2
If arrcount(i, j) = "" Then
If arrcount(i, j - 1) = "A" Then
CA = CA + 1
ElseIf arrcount(i, j - 1) = "B" Then
CB = CB + 1
Else
CC = CC + 1
End If
ElseIf arrcount(i, j + 1) = "" Then
If arrcount(i, j - 1) = "A" Then
CA = CA + (1 / 2)
ElseIf arrcount(i, j - 1) = "B" Then
CB = CB+ (1 / 2)
Else
CC = CC + (1 / 2)
End If
If arrcount(i, j) = "A" Then
CA= CA + (1 / 2)
ElseIf arrcount(i, j) = "B" Then
CB = CB + (1 / 2)
Else
CC = CC+ (1 / 2)
End If
Else
CA = CA + (1 / 3)
CB = CB+ (1 / 3)
CC = CC + (1 / 3)
End If
Next j
Next i
Thanks again for the wisdom you are sharing.