Edit VBA to count ties.

emperorgenghiskhan

New Member
Joined
Oct 30, 2020
Messages
3
Office Version
  1. 2010
Platform
  1. Windows
I would like to have the VBA be able to generate a Tie/Draw column for instances where the score is tied.
Thanks in advance

The code used in the VBA was what was posted by Peter_SSs in this thread

VBA Code:
Sub ResultSummary_v2()
  Dim d1 As Object, d2 As Object
  Dim a As Variant, ky As Variant
  Dim sPlayers As String, tmp As String, P1 As String
  Dim i As Long, j As Long, winner As Long, nr As Long

  Set d1 = CreateObject("Scripting.Dictionary")
  d1.CompareMode = 1
  Set d2 = CreateObject("Scripting.Dictionary")
  d2.CompareMode = 1
  a = Range("A2", Range("D" & Rows.Count).End(xlUp)).Value
  For i = 1 To UBound(a)
    If Len(a(i, 1)) * Len(a(i, 2)) > 0 Then
      If a(i, 1) > a(i, 2) Then
        tmp = a(i, 1)
        a(i, 1) = a(i, 2)
        a(i, 2) = tmp
        tmp = a(i, 3)
        a(i, 3) = a(i, 4)
        a(i, 4) = tmp
      End If
      winner = IIf(a(i, 3) > 0, 1, 2)
      For j = 1 To 2
        If d2.exists(a(i, j)) Then
          d2(a(i, j)) = Split(d2(a(i, j)), ";")(0) + 1 & ";" & Split(d2(a(i, j)), ";")(1) + IIf(winner = j, 1, 0)
        Else
          d2(a(i, j)) = "1;" & IIf(winner = j, 1, 0)
        End If
      Next j
      sPlayers = a(i, 1) & ";" & a(i, 2)
      If d1.exists(sPlayers) Then
        If winner = 1 Then
          d1(sPlayers) = ";;" & Split(d1(sPlayers), ";")(2) + 1 & ";;" & Split(d1(sPlayers), ";")(4)
        Else
          d1(sPlayers) = ";;" & Split(d1(sPlayers), ";")(2) & ";;" & Split(d1(sPlayers), ";")(4) + 1
        End If
      Else
        d1(sPlayers) = IIf(winner = 1, ";;1;;0", ";;0;;1")
      End If
    End If
  Next i
  Application.ScreenUpdating = False
  Columns("I:P").Clear
  With Range("I2:J2").Resize(d2.Count)
    .Rows(0).Resize(, 6).Value = Array("Player", "Played", "Won", "Lost", "% Won", "Rank")
    .Rows(0).Resize(, 6).Font.Bold = True
    .Value = Application.Transpose(Array(d2.keys, d2.Items))
    .Sort Key1:=.Columns(1), Order1:=xlAscending, Header:=xlNo
    .Columns(2).TextToColumns DataType:=xlDelimited, ConsecutiveDelimiter:=False, Semicolon:=True, Comma:=False, Space:=False, Other:=False
    .Offset(, 3).Resize(, 1).FormulaR1C1 = "=RC[-2]-RC[-1]"
    .Offset(, 4).Resize(, 1).FormulaR1C1 = "=RC[-2]/RC[-3]"
    .Offset(, 4).Resize(, 1).NumberFormat = "0.00%"
    .Offset(, 5).Resize(, 1).FormulaR1C1 = "=RANK(RC[-1],R" & .Row & "C[-1]:R" & .Row + .Rows.Count - 1 & "C[-1])"
    a = .Columns(1).Value
  End With
  nr = UBound(a) + 4
  Range("I" & nr - 1).Resize(, 7).Value = Array("Player", "", "Opponent", "Played", "Won", "Lost", "% Won")
  Range("I" & nr - 1).Resize(, 7).Font.Bold = True
  For i = 1 To UBound(a)
    d2.RemoveAll
    P1 = a(i, 1)
    For Each ky In d1.keys
      Select Case True
        Case Split(ky, ";")(0) = P1
          d2(Split(ky, ";")(1)) = Mid(d1(ky), 2)
        Case Split(ky, ";")(1) = P1
          d2(Split(ky, ";")(0)) = ";" & Split(d1(ky), ";")(4) & ";" & Split(d1(ky), ";")(2)
      End Select
    Next ky
    With Range("K" & nr & ":L" & nr).Resize(d2.Count)
      .Cells(1, -1).Resize(, 2).Value = Array(P1, "v")
      .Value = Application.Transpose(Array(d2.keys, d2.Items))
      .Sort Key1:=.Columns(1), Order1:=xlAscending, Header:=xlNo
      .Columns(2).TextToColumns DataType:=xlDelimited, ConsecutiveDelimiter:=True, Semicolon:=True, Comma:=False, Space:=False, Other:=False
      .Offset(, 1).Resize(, 1).FormulaR1C1 = "=RC[1]+RC[2]"
      With .Offset(, 4).Resize(, 1)
        .NumberFormat = "0.00%"
        .FormulaR1C1 = "=RC[-2]/RC[-3]"
      End With
      nr = nr + d2.Count + 1
    End With
  Next i
  Columns("I:O").AutoFit
  Application.ScreenUpdating = True
End Sub





One On One.xlsm
ABCDEFGHIJKLMNO
1Player 1Player 2WinnerLoserPlayerPlayedWonLost% WonRank
2Darryl Strawberry21150.00%5
3Tom SeaverDwight Gooden013Dwight Gooden53260.00%4
4Dwight GoodenTom Seaver20Gary Carter220100.00%1
5Darryl StrawberryNolan Ryan870John Olerud64266.67%2
6Nolan RyanTom Seaver028Keith Hernandez31233.33%8
7Gary CarterNolan Ryan590Lenny Dykstra31233.33%8
8Keith HernandezDwight Gooden016Mike Piazza42250.00%5
9Lenny DykstraTom Seaver410Nolan Ryan52340.00%7
10Mike PiazzaRoberto Alomar1330Roberto Alomar32166.67%2
11Roberto AlomarMike Piazza340Tom Seaver72528.57%10
12John OlerudLenny Dykstra400
13Tom SeaverJohn Olerud0129PlayerOpponentPlayedWonLost% Won
14Darryl StrawberryNolan Ryan070Darryl StrawberryvNolan Ryan21150.00%
15Gary CarterJohn Olerud270
16Lenny DykstraJohn Olerud013Dwight GoodenvKeith Hernandez21150.00%
17Roberto AlomarMike Piazza60Tom Seaver32166.67%
18John OlerudKeith Hernandez380
19Mike PiazzaJohn Olerud20Gary CartervJohn Olerud110100.00%
20Keith HernandezDwight Gooden940Nolan Ryan110100.00%
21Nolan RyanTom Seaver160
22Dwight GoodenTom Seaver018John OlerudvGary Carter1010.00%
23Keith Hernandez110100.00%
24Lenny Dykstra220100.00%
25Mike Piazza1010.00%
26Tom Seaver110100.00%
27
28Keith HernandezvDwight Gooden21150.00%
29John Olerud1010.00%
30
31Lenny DykstravJohn Olerud2020.00%
32Tom Seaver110100.00%
33
34Mike PiazzavJohn Olerud110100.00%
35Roberto Alomar31233.33%
36
37Nolan RyanvDarryl Strawberry21150.00%
38Gary Carter1010.00%
39Tom Seaver21150.00%
40
41Roberto AlomarvMike Piazza32166.67%
42
43Tom SeavervDwight Gooden31233.33%
44John Olerud1010.00%
45Lenny Dykstra1010.00%
46Nolan Ryan21150.00%
Sheet1
Cell Formulas
RangeFormula
L2:L11L2=J2-K2
O43:O46,O41,O37:O39,O34:O35,O31:O32,O28:O29,O22:O26,O19:O20,O16:O17,O14,M2:M11M2=K2/J2
N2:N11N2=RANK(M2,M$2:M$11)
L14,L43:L46,L41,L37:L39,L34:L35,L31:L32,L28:L29,L22:L26,L19:L20,L16:L17L14=M14+N14
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest

Forum statistics

Threads
1,223,236
Messages
6,170,915
Members
452,366
Latest member
TePunaBloke

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