Trying To Break ties

Chesley

New Member
Joined
Jan 12, 2016
Messages
14
I have a column with a number of integers in column A, which has a number of ties in it. I need to be able to break the ties by using values in B, and if there is still ties, then got column c, and again, if there is ties go to column D,etc ( up to 7 columns with values to be used to break the Ties). I'm trying to do this in vba, however being new to vba , I haven't been able to get this to work, I find it gets to convoluted when I get to checking the second column of values to try and break the ties, I have all values stored in arrays. As you can see below the first "77" tie is broken by the next column "36" but the next two 77 ties are not broken until the last possible check.

77 36 24 12 41 27 13 5
77 37 23 11 40 27 13 4
77 37 23 11 40 27 13 5

I've been trying to resolve this for a couple of weeks, sad to say I haven't, but the good news is I'm learning a lot about Excel VBA. If someone can point me in the right direction it would be appreciated.

Thanks
 
I'm not sure if your data is always sorted by final score but it doesn't need to be with my code. Here is the same data in jumbled order with code run over that data too.

Excel Workbook
ABCDEFGHIJKLMNOPQRSTUVWXYZAAAB
1#FirstLastHDCPSkins123456789101112131415161718OutInTotalNetPos
210III6N4654555455553455454341847810
33CCC4Y464555444654343335413677733 (Play-off)
46EEE6Y2333553655453444310354277716
54CCCCC4Y464555444654343335413677733 (Play-off)
612KKK9N6535555454347445754343867712
79HHH8N474455545555345545434184769
814MMM6N6756463545654554254641878113 (Play-off)
91AAA3Y634534544444454444383775721
107FFF7N455535445646334435403878717
115DDD5Y554545445444354435413677725
1211JJJ7N6544365636743553364242847711
132BBB4Y634534544444553454383876722
148GGG8Y652656545533554464443983758
1513LLL6N6756463545654554254641878113 (Play-off)
Sheet3
 
Upvote 0

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
Peter, your ABSOLUTELY MAGICIAL, I looked at the quantity of your code and thought, "No way did he resolve this with only 46 lines of code" WOW, I can't tell you how happy I am to see this.
But of course, I don't understand a lot of it. I looked at dictionary's and arraylists but didn't really understand how useful they could be and how to utilize them. None of these are mentioned in either of the 3 courses on Excel VBA I'm taking. Could you spend a little more time with me and explain some of the code?
Questions
1. I understand the TieBreakColsArr and what your doing except the evaluate part, I mean I know that your evaluating the last six, last three etc, but when I add the array to the watch window I not sure what its telling me at the evaluate parts.
2. I see a and b are arrays, one with the row values and the other with the TieBreakColsArr array values and your using s to build a delimited string, after that I'm kind of lost. Could you explain please.
Again Peter Thanks , this is absolutely GREAT, I would never of envisioned trying to resolve this this way. You taught me a lot here, especially do more thinking before you start writing the code.
 
Upvote 0
Peter, your ABSOLUTELY MAGICIAL, I looked at the quantity of your code and thought, "No way did he resolve this with only 46 lines of code" WOW, I can't tell you how happy I am to see this.
You are welcome. :)



1. I understand the TieBreakColsArr and what your doing except the evaluate part, I mean I know that your evaluating the last six, last three etc, but when I add the array to the watch window I not sure what its telling me at the evaluate parts.
The evaluate part makes an array of the relevant column numbers (even though it uses rows() to do it) for the particular sum. If we look at TieBreakColsArr(8) = Evaluate("row(7:9)")
It makes an array of the numbers (7, 8, 9)
This is then used in the line
b(i, j) = Format(Application.Sum(Application.Index(a, i, TieBreakColsArr(j))), "000")
which becomes like
b(i, j) = Format(Application.Sum(Application.Index(a, i, {7,8,9})), "000")
So for the first row of data (i=1) the Sum adds (in pseudo code) Index(all the data, row 1, columns 7, 8 & 9) to get the front 9 last 3 total.


2. I see a and b are arrays, one with the row values and the other with the TieBreakColsArr array values and your using s to build a delimited string, after that I'm kind of lost. Could you explain please.
You are right about the delimited string. (It didn't really need all the delimiters but that made it easier for me to see what was happening)
So, for the first player from the post #20 data, their sting is:

|075|037|025|012|004|038|025|013|004|004|004|004|004|005|004|004|004|004|004|004|005|004|003|005|004|003|006

This represents, in order of importance, the 27 tie-break* amounts:
Total|Back 9 total|Back 9 last 6|Back 9 last 3|... etc

By formatting them all as 3-digits, all the strings are of identical length & can therefore be sorted in alphabetical order to achieve our goal.

Each of these strings is added** into a "Sorted List" (as a Key) along with its row number (as an Item). A sorted list automatically orders its members from smallest to largest as they are entered.

Once we have processed all the rows into the Sorted List we just extract the Items back out of the Sorted List from the first (smallest) Key to the largest. Each time we use the Item (row number(s)) to put the position of that player into the results array (array Pos)
The 'Inc' variable is used to keep track of how many position numbers we have skipped due to ties.

* We actually have some duplicated tie-breakers that could have been eliminated but I felt it easier to leave them in for code understanding. For example
TieBreakColsArr(5) = 18 is using hole #18 as a tie-break, as is TieBreakColsArr(10), being the first one generated by
Code:
  For i = 18 To 1 Step -1                     'Individual hole cols in reverse
    TieBreakColsArr(28 - i) = i
  Next i
So TieBreakColsArr(10) will never get used to break a tie, as that tie would have already been broken by TieBreakColsArr(5)


** Actually, if one of these strings is already in the Sorted List, then all we do is add the new row number to the existing row number(s) already stored as the Item for that Key:
Code:
    If SL.ContainsKey(s) Then
      SL(s) = SL(s) & " " & i


Hope that made some sense. Usually easier to do than to describe. :)



Great work, Peter ...

... and full marks for patience! :)

Regards,
Thanks Rick. The solution is of course largely down to you introducing me to Sorted Lists recently.
The patience was because I had an interest in the problem, figuring I could get some practice in with these Sorted Lists. :)
 
Upvote 0
Peter, I've been looking at your solution and Have another question, the line "b(i, j) = Format(Application.Sum(Application.Index(a, i, TieBreakColsArr(j))), "000")" It sums the "lastsix", "lastthree" etc, so if there is nothing to sum it just formats the string as "000" , is that correct, the reason I'm asking is to determine the net score ranking , which I initially thought was straight forward and I could just modify your code and use the Net totals, but now find out there is a different process, the lastsix has to be multiplied by 1/6 of the players HDCP, the lastthree by 1/3 of the players HDCP and each 9 (in and out) by 1/2 of the players HDCP. My attempt to modify your code is a total failure, can this be done with your existing code????
Thanks
 
Upvote 0
Hi and welcome to the MrExcel Message Board.

In VBA terms, whet do you want to happen when you have located a tie (or not)? Do you want a flag to be set in an array element or something?

The trick to these problems is to steer away from a detailed solution. Down that path lies madness. Basically, all you need to is:

1. Combine all the numbers together into a string separated by a character to stop the columns getting mixed up. E.G 77-36-24-12-41-27-13-5
2. Sort that string into order.
3. See if a string matches either of its neighbours.

An alternative to steps 2 and 3 would be to count up the number of occurrences of each string and report the results. Which is the better option depends on how you need the answers.

In this strategy I would replace step one with a ranking method that generates a value.
Code:
=RANK(A2,$A$2:$A$4,1)*100^7+RANK(B2,$B$2:$B$4,1)*100^6+RANK(C2,$C$2:$C$4,1)*100^5+RANK(D2,$D$2:$D$4,1)*100^4+RANK(E2,$E$2:$E$4,1)*100^3+RANK(F2,$F$2:$F$4,1)*100^2+RANK(G2,$G$2:$G$4,1)*100^1+RANK(H2,$H$2:$H$4,1)*100^0
Then evaluate that result using the RANK function again.

the factor of 100 is dependent on assuming scores are integers from 0-99
 
Upvote 0
Peter, I've been looking at your solution and Have another question, the line "b(i, j) = Format(Application.Sum(Application.Index(a, i, TieBreakColsArr(j))), "000")" It sums the "lastsix", "lastthree" etc, so if there is nothing to sum it just formats the string as "000" , is that correct,
That would be correct, BUT if there is "nothing to sum" wouldn't that mean the player did not compete or did not complete the round? If that was the case, presumably they do not have a 'Total' or 'Net' score in the sheet in the first place & we could use that fact to eliminate them from the calculation altogether?



.. now find out there is a different process, the lastsix has to be multiplied by 1/6 of the players HDCP, the lastthree by 1/3 of the players HDCP and each 9 (in and out) by 1/2 of the players HDCP.
Are you sure those fractions are correct? They don't seem logical to me. Why would "last three" have less weighting (1/3) than "last nine" (1/2) but more weighting than "last six" (1/6)?

To me it would seem more logical to multiply by say
1/2 for 9 holes
1/3 for 6 holes
1/6 for 3 holes


Perhaps you could clarify all the above points and also give a new small sample set, including expected results with explanation of at least some of those results.
If such data exists, also include at least one row where "so if there is nothing to sum" ..


Also confirm (or clarify) that
- 'Net' score is the primary ranking value
- 'Total' is not used at all in ranking/tie-breaking
 
Last edited:
Upvote 0
Peter, by nothing to sum I was thinking that the sum function in this case was only summing the 13:18, 16:18,4:9 and 7:9, and the rest of the values would be just formatted with the "000", am I wrong here. We don't have to worry about someone who doesn't finish they are eliminated from the competition. I went back and looked and you were right the actual wording is "To break a tie in net competition follow the same procedure as gross score and deduct the appropriate portion of the course handicap and include the fractions.
i) last 18 holes less full course handicap
ii) last 9 holes (10-18) less 1/2 course handicap (9/18)
iii) last 6 holes (13-18) less 1/3 course handicap (6/18
iv) last 3 holes (16-18) less 1/6 course handicap (3/18)"
I assume it would do the front nine the same, although it doesn't emphatically state so.

I don't have any data for the net but I can make up some and post tomorrow. And Yes the net score is the primary value used in ranking, the gross total is not used.

Thanks for your help Peter
 
Upvote 0
Peter, by nothing to sum I was thinking that the sum function in this case was only summing the 13:18, 16:18,4:9 and 7:9, and the rest of the values would be just formatted with the "000", am I wrong here.
No, you are not wrong. Every sub-result is formatted as "000" whether it is the sum of several holes or just an individual number. I gave a fairly detailed worked example, in post #24.


ii) last 9 holes (10-18) less 1/2 course handicap (9/18)
iii) last 6 holes (13-18) less 1/3 course handicap (6/18
iv) last 3 holes (16-18) less 1/6 course handicap (3/18)
This makes much more sense.
"last 6 holes (13-18) less 1/3 course handicap (6/18)" is quite different to "lastsix has to be multiplied by 1/6 of the players HDCP"


I think I understand what is required now. I'll have a think about it & try to put something together when I can.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,382
Messages
6,124,618
Members
449,175
Latest member
Anniewonder

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top