Winning a Loosing Streak

wladoD

New Member
Joined
Sep 18, 2017
Messages
5
Hi Guys,

I do have a question about winning and loosing streak in my hockey league.

I have data where player can play home or away.
What would be the most efficient way to count winning and loosing streak?
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
If you have a column to record Win/Lose then you can use something like this:


Book1
AB
1ResultStreak
2WinWin 1
3WinWin 2
4LoseLose 1
5LoseLose 2
6LoseLose 3
7WinWin 1
8WinWin 2
9WinWin 3
10LoseLose 1
11WinWin 1
12WinWin 2
13LoseLose 1
14LoseLose 2
15LoseLose 3
16LoseLose 4
Sheet1
Cell Formulas
RangeFormula
B2{=$A2&" "&(ROW($B2)-MAX(IF($A$1:$A1<>$A2,ROW($A$1:$A1))))}
Press CTRL+SHIFT+ENTER to enter array formulas.


WBD
 
Upvote 0
Streak.png
 
Upvote 0
My data is bit more complicated.

Player can play away and home matches.

Outcomes for results are WRT - WOT - WPP these are all Wins
LRT , LOT, LPP these are all Loses
 
Upvote 0
With the level of complication, I think you'll need VBA and not a formula:


Book1
ABCDEFGHIJKLMNO
1IDROUNDTEAM 1PLAYER 1HARPLAYER 2TEAM 2DATE
231. RoundEdmonton OilersTosino23WRT21RTLRTwladoDEdmonton Oilers22-Jul-17Tosino23-2
344QuaterfinalAnaheim DucksalphafxdbLRT46RTWRTdawo043St. Louis Blues23-Jul-17wladoD1
445QuaterfinalEdmonton OilersTosino23LRT02RTWRTwladoDChicago Blackhawks24-Jul-17alphafxdb-3
546QuaterfinalSt. Louis Bluesdawo043WRT32RTLRTalphafxdbAnaheim Ducks25-Jul-17dawo043-3
647QuaterfinalChicago BlackhawkswladoDWRT10RTLRTTosino23Edmonton Oilers26-Jul-17Biculinho-1
748QuaterfinalAnaheim DucksalphafxdbLPP12PPWPPdawo043St. Louis Blues27-Jul-17FlatOut32323
849SemifinalWashington CapitalsBiculinhoLRT15RTWRTwladoDChicago Blackhawks28-Jul-17
950SemifinalNashville PredatorsFlatOut3232WRT62RTLRTdawo043St. Louis Blues29-Jul-17
1051SemifinalChicago BlackhawkswladoDWRT52RTLRTBiculinhoWashington Capitals30-Jul-17
1152SemifinalSt. Louis Bluesdawo043LRT15RTWRTFlatOut3232Nashville Predators31-Jul-17
1253SemifinalWashington CapitalsBiculinhoWRT10RTLRTwladoDChicago Blackhawks01-Aug-17
1354SemifinalNashville PredatorsFlatOut3232WRT43RTLRTdawo043St. Louis Blues02-Aug-17
1455SemifinalChicago BlackhawkswladoDWRT51RTLRTBiculinhoWashington Capitals03-Aug-17
Sheet1


Code:
Public Sub FindStreaks()

Dim lastPlayer As Long
Dim thisPlayer As Long
Dim lastRow As Long
Dim thisRow As Long
Dim lastResult As String
Dim thisResult As String
Dim currentStreak As Long

' Find the last row of data
lastRow = Cells(Rows.Count, "A").End(xlUp).Row

' Find the last row of player names
lastPlayer = Cells(Rows.Count, "N").End(xlUp).Row

' Process each player
For thisPlayer = 2 To lastPlayer
    ' Blank out the last result and streak
    lastResult = ""
    currentStreak = 0
    
    ' Process the data rows from bottom to top
    For thisRow = lastRow To 2 Step -1
        ' Determine whether the current player won, lost or didn't play
        thisResult = ""
        If Cells(thisRow, "D").Value = Cells(thisPlayer, "N").Value Then
            If Left$(Cells(thisRow, "E").Value, 1) = "W" Then
                thisResult = "W"
            Else
                thisResult = "L"
            End If
        ElseIf Cells(thisRow, "J").Value = Cells(thisPlayer, "N").Value Then
            If Left$(Cells(thisRow, "I").Value, 1) = "W" Then
                thisResult = "W"
            Else
                thisResult = "L"
            End If
        End If
        
        ' If this player played then either accumulate or terminate the streak
        If thisResult <> "" Then
            If lastResult = "" Then
                lastResult = thisResult
                currentStreak = 1
            Else
                If thisResult = lastResult Then
                    currentStreak = currentStreak + 1
                Else
                    Exit For
                End If
            End If
        End If
    Next thisRow
    
    ' Choose one of the lines below
    Cells(thisPlayer, "O").Value = CStr(currentStreak) & " " & lastResult
    Cells(thisPlayer, "O").Value = currentStreak * IIf(lastResult = "L", -1, 1)
Next thisPlayer

End Sub

WBD
 
Upvote 0
Can you please advice where to add VBA code and how will it work?
Where will I see the result?
 
Upvote 0
[TABLE="width: 128"]
<colgroup><col span="2"></colgroup><tbody>[TR]
[TD]Team1[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]WRT[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]LRT[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]LRT[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]LRT[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]WRT[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]WRT[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]LRT[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]LRT[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]LRT[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]LRT[/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]

I am able to dynamically extract the last matches played. would it be possible to use regular formula?
 
Upvote 0
For the VBA, press [Alt]+[F11] to bring up the editor, select Insert->Module and paste the code above. Close the editor and go back to the sheet. Press [Alt]+[F8] to select and run the macro.

WBD
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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