How to show previous 10 games played

groceryguy306

New Member
Joined
May 19, 2022
Messages
20
Office Version
  1. 2013
Platform
  1. Windows
Hello
I have a chart of hockey teams and on a different tab i would like to show the previous 10 games played for each team and who the winner was, but having games in my data field sorted in to home columns and away columns has proved difficult. I was reading some other posts and many mentioned using the "Lambda" formula, but it is not available in my version of excel
 

Attachments

  • Capture.PNG
    Capture.PNG
    72.9 KB · Views: 21

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
DateVisitorGoals VHomeGoals HOTTotalOV / UDGoalsWinner
2023-10-10Chicago Blackhawks4Pittsburgh Penguins26Under4-2Chicago Blackhawks
2023-10-10Nashville Predators3Tampa Bay Lightning58Over3-5Tampa Bay Lightning
2023-10-10Seattle Kraken1Vegas Golden Knights45Under1-4Vegas Golden Knights
2023-10-11Chicago Blackhawks1Boston Bruins34Under1-3Boston Bruins
2023-10-11Ottawa Senators3Carolina Hurricanes58Over3-5Carolina Hurricanes
2023-10-11Winnipeg Jets3Calgary Flames58Over3-5Calgary Flames
2023-10-11Colorado Avalanche5Los Angeles Kings27Over5-2Colorado Avalanche
2023-10-11Montreal Canadiens5Toronto Maple Leafs6SO11Over5-6Toronto Maple Leafs
2023-10-11Edmonton Oilers1Vancouver Canucks89Over1-8Vancouver Canucks
2023-10-12New York Rangers5Buffalo Sabres16Under5-1New York Rangers
2023-10-12Philadelphia Flyers4Columbus Blue Jackets26Under4-2Philadelphia Flyers
2023-10-12St. Louis Blues1Dallas Stars2SO3Under1-2Dallas Stars
2023-10-12Florida Panthers0Minnesota Wild22Under0-2Minnesota Wild
2023-10-12Detroit Red Wings3New Jersey Devils47Over3-4New Jersey Devils
2023-10-12Seattle Kraken0Nashville Predators33Under0-3Nashville Predators
2023-10-12Vegas Golden Knights4San Jose Sharks15Under4-1Vegas Golden Knights
2023-10-13Arizona Coyotes4New Jersey Devils3SO7Over4-3Arizona Coyotes
2023-10-13Pittsburgh Penguins4Washington Capitals04Under4-0Pittsburgh Penguins
2023-10-14Nashville Predators2Boston Bruins35Under2-3Boston Bruins
2023-10-14New York Rangers3Columbus Blue Jackets58Over3-5Columbus Blue Jackets
2023-10-14Tampa Bay Lightning4Detroit Red Wings610Over4-6Detroit Red Wings
2023-10-14Vancouver Canucks4Edmonton Oilers37Over4-3Vancouver Canucks
2023-10-14Carolina Hurricanes6Los Angeles Kings5SO11Over6-5Carolina Hurricanes
2023-10-14Chicago Blackhawks2Montreal Canadiens35Under2-3Montreal Canadiens
2023-10-14Buffalo Sabres2New York Islanders35Under2-3New York Islanders
2023-10-14Philadelphia Flyers2Ottawa Senators57Over2-5Ottawa Senators
2023-10-14Calgary Flames2Pittsburgh Penguins57Over2-5Pittsburgh Penguins
2023-10-14Colorado Avalanche2San Jose Sharks1SO3Under2-1Colorado Avalanche
2023-10-14Seattle Kraken1St. Louis Blues2SO3Under1-2St. Louis Blues
2023-10-14Minnesota Wild4Toronto Maple Leafs711Over4-7Toronto Maple Leafs
2023-10-14Anaheim Ducks1Vegas Golden Knights45Under1-4Vegas Golden Knights
2023-10-14Florida Panthers4Winnipeg Jets610Over4-6Winnipeg Jets
2023-10-15Carolina Hurricanes3Anaheim Ducks69Over3-6Anaheim Ducks
 
Upvote 0
Can you manually create what the results should look like and post that with XL2BB as well?
 
Upvote 0
try this... all done with Record Macro. only written piece of the vba is changing the reference to cell AA1 so it allows the spreadsheet to become a variable instead of a fixed range. you can open the macro editor, hit F8 to see the macro run line-by-line to see exactly what it is doing. Cheers!

VBA Code:
''assume you have these two sheets
''sheet1 is the data data you're currently showing, including the drop-down
''sheet2 will be used to do the work in the macro.

''assume cell K2 is the result of your dropdown.
 
'' assume your "Date" is in cell B5, "Visitor" in C5, "Home" in E5, etc...
''assume your data starts in B6 and below.

Sub macro12___Run_all__()
    Application.Run " Macro14"
    Application.Run " Macro22"
    Application.Run " Macro23"
    Application.Run " Macro24"
    Application.Run " Macro26"
    Application.Run " Macro28"
    Application.Run " Macro31"
    Application.Run " Macro32"
    Application.Run " Macro33"
  
    Application.Run " Macro35"
    Application.Run " Macro36"
    Application.Run " Macro38"
End Sub

Sub Macro14()
'clear all of sheet2 for a fresh start
    Sheets("Sheet2").Select
    Application.Goto Reference:="R1C1"
    ActiveCell.Columns("A:Z").EntireColumn.Select
    Application.CutCopyMode = False
    Selection.Delete Shift:=xlToLeft
    Selection.Delete Shift:=xlToLeft
    Selection.Delete Shift:=xlToLeft
    Application.Goto Reference:="R1C1"

''copy a to z of sheet1
    Sheets("Sheet1").Select
    Application.Goto Reference:="R1C1"
    ActiveCell.Columns("A:Z").EntireColumn.Select
    Selection.Copy
''paste to sheet2 as values, formats
    Sheets("Sheet2").Select
    Application.Goto Reference:="R1C1"
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
    Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
End Sub

Sub Macro22()

'clear all of AA first
    Sheets("Sheet2").Select
    Application.Goto Reference:="R1C1"
    Application.Goto Reference:="R1C27"
    ActiveCell.Columns("A:Z").EntireColumn.Select
    Selection.Delete Shift:=xlToLeft
    Application.Goto Reference:="R1C1"
End Sub

Sub Macro23()

'find last row in data, paste in cell AA1, to be used later
    Sheets("Sheet2").Select
    Application.Goto Reference:="R1C1"
    ActiveCell.SpecialCells(xlLastCell).Select
    ActiveCell.Offset(2, 0).Range("A1").Select
    Selection.End(xlToLeft).Select
    Selection.Clear
    Selection.FormulaR1C1 = "=ROW()"
    Selection.Copy
    Application.CutCopyMode = False
    Selection.Copy
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
    Application.CutCopyMode = False
    Selection.Cut
    Application.Goto Reference:="R1C27"
    ActiveSheet.Paste
End Sub

Sub Macro24()
'set up formulas to look for teams, dates, winners
    Sheets("Sheet2").Select
    Application.Goto Reference:="R1C28"
    ActiveCell.FormulaR1C1 = "''add"
    ActiveCell.Offset(1, 0).Range("A1").Select
    ActiveCell.FormulaR1C1 = "''row_index"
    ActiveCell.Offset(-1, 1).Range("A1").Select
    ActiveCell.FormulaR1C1 = "''find if true in K2"
    ActiveCell.Offset(1, 0).Range("A1").Select
    ActiveCell.FormulaR1C1 = "'visitor"
    ActiveCell.Offset(-1, 2).Range("A1").Select
    ActiveCell.FormulaR1C1 = "''find if true in K2"
    ActiveCell.Offset(1, 0).Range("A1").Select
    ActiveCell.FormulaR1C1 = "''home"
    ActiveCell.Offset(-1, 1).Range("A1").Select
    ActiveCell.FormulaR1C1 = "'''find team, regardless"
    ActiveCell.Offset(1, 0).Range("A1").Select
    ActiveCell.FormulaR1C1 = "if Visitor or Home"
    ActiveCell.Offset(-1, 1).Range("A1").Select
    ActiveCell.FormulaR1C1 = "'''find"
    ActiveCell.Offset(1, 0).Range("A1").Select
    ActiveCell.FormulaR1C1 = "winner"
    ActiveCell.Offset(-1, 1).Range("A1").Select
    ActiveCell.FormulaR1C1 = "''find date"
    ActiveCell.Offset(1, 0).Range("A1").Select
    ActiveCell.FormulaR1C1 = "game was played"
    ActiveCell.Offset(1, 0).Range("A1").Select
    Application.Goto Reference:="R6C28"
    Selection.FormulaR1C1 = "=ROW()"
    ActiveCell.Offset(0, 1).Range("A1").Select
    Selection.FormulaR1C1 = "=R2C11=RC[-26]"
    ActiveCell.Offset(0, 2).Range("A1").Select
    Selection.FormulaR1C1 = "=R2C11=RC[-26]"
    ActiveCell.Offset(0, 1).Range("A1").Select
    Selection.FormulaR1C1 = "=IF(RC[-3]=TRUE,RC[-29],IF(RC[-1]=TRUE,RC[-27],""""))"
    ActiveCell.Offset(0, 1).Range("A1").Select
    Selection.FormulaR1C1 = "=IF(RC[-1]="""","""",RC[-22])"
    ActiveCell.Offset(0, 1).Range("A1").Select
    Selection.FormulaR1C1 = "=IF(RC[-2]="""","""",RC[-32])"
    Application.Goto Reference:="R6C28"
    ActiveCell.Range("A1:G1").Select
    Selection.Copy
'''    ActiveCell.Range("A1:G20").Select
''manually change this to be referencing cell AA1
    ActiveCell.Range("A1:G" & Range("aa1")).Select
    ActiveSheet.Paste
    Calculate
    Selection.Copy
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
    Application.CutCopyMode = False
End Sub

Sub Macro26()

'''parse AH to general format, so to get rid of the residual from the formulas
    Sheets("Sheet2").Select
    Application.Goto Reference:="R1C34"
    ActiveCell.Columns("A:A").EntireColumn.Select
    Selection.TextToColumns Destination:=ActiveCell, DataType:=xlDelimited, TextQualifier:=xlNone, ConsecutiveDelimiter:=False, Tab:=False, Semicolon:=False, Comma:=False, Space:=False, Other:=False, FieldInfo:=Array(1, 1), TrailingMinusNumbers:=True
End Sub

Sub Macro28()
''''format AH as date
    Sheets("Sheet2").Select
    Application.Goto Reference:="R1C34"
    ActiveCell.Columns("A:A").EntireColumn.Select
    Selection.NumberFormat = "[$-en-US]dd-mmm-yyyy;@"
End Sub

Sub Macro31()
'select AB to AH, sort AH newest first
    Sheets("Sheet2").Select
    Application.Goto Reference:="R6C28"
'''    ActiveCell.Range("A1:G427").Select
    ActiveCell.Range("A1:G" & Range("aa1")).Select
    ActiveSheet.Sort.SortFields.Clear
    ActiveSheet.Sort.SortFields.Add2 Key:=ActiveCell.Offset(0, 6).Range("A1:A" & Range("aa1")), SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:=xlSortNormal
    With ActiveSheet.Sort
'''        .SetRange ActiveCell.Range("A1:G425")
        .SetRange ActiveCell.Range("A1:G" & Range("aa1"))
        .Header = xlGuess
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With
End Sub

Sub Macro32()
'find the most recent games in AI
    Sheets("Sheet2").Select
    Application.Goto Reference:="R1C35"
    ActiveCell.FormulaR1C1 = "'all most "
    ActiveCell.Offset(1, 0).Range("A1").Select
    ActiveCell.FormulaR1C1 = "recent games"
    ActiveCell.Offset(1, 0).Range("A1").Select
    Application.Goto Reference:="R6C35"
    Selection.FormulaR1C1 = "=COUNTIF(R1C32:RC[-3],RC[-3])"
    Selection.Copy
    ActiveCell.Range("A1:A" & Range("aa1")).Select
    ActiveSheet.Paste
    Application.CutCopyMode = False
    Calculate
    Selection.Copy
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
End Sub

Sub Macro33()
'color the winner green
    Application.Goto Reference:="R1C33"
    ActiveCell.Range("A1:A38").Select
    With Selection.Interior
        .Pattern = xlSolid
        .PatternColorIndex = xlAutomatic
        .Color = 3407718
        .TintAndShade = 0
        .PatternTintAndShade = 0
    End With
    Selection.Borders(xlDiagonalDown).LineStyle = xlNone
    Selection.Borders(xlDiagonalUp).LineStyle = xlNone
    With Selection.Borders(xlEdgeLeft)
        .LineStyle = xlContinuous
        .ColorIndex = xlAutomatic
        .TintAndShade = 0
        .Weight = xlThin
    End With
    With Selection.Borders(xlEdgeTop)
        .LineStyle = xlContinuous
        .ColorIndex = xlAutomatic
        .TintAndShade = 0
        .Weight = xlThin
    End With
    With Selection.Borders(xlEdgeBottom)
        .LineStyle = xlContinuous
        .ColorIndex = xlAutomatic
        .TintAndShade = 0
        .Weight = xlThin
    End With
    With Selection.Borders(xlEdgeRight)
        .LineStyle = xlContinuous
        .ColorIndex = xlAutomatic
        .TintAndShade = 0
        .Weight = xlThin
    End With
    Selection.Borders(xlInsideVertical).LineStyle = xlNone
    With Selection.Borders(xlInsideHorizontal)
        .LineStyle = xlContinuous
        .ColorIndex = xlAutomatic
        .TintAndShade = 0
        .Weight = xlThin
    End With
End Sub


Sub Macro35()
''''find only the ten most recent games,
''if less than ten games, keep only those games
  
    Application.Goto Reference:="R1C36"
    ActiveCell.FormulaR1C1 = "'ten most "
    ActiveCell.Offset(1, 0).Range("A1").Select
    ActiveCell.FormulaR1C1 = "recent games"
    ActiveCell.Offset(1, 0).Range("A1").Select
    Application.Goto Reference:="R1C37"
    ActiveCell.FormulaR1C1 = "Keep_or_Clear"
    ActiveCell.Offset(1, 0).Range("A1").Select
    Application.Goto Reference:="R6C36"
    Selection.FormulaR1C1 = "=IF(RC[-1]<11,RC[-4],"""")"
    ActiveCell.Offset(0, 1).Range("A1").Select
    Selection.FormulaR1C1 = "=IF(RC[-1]=R2C11,""1_Keep"",""2_Clear"")"
    Application.Goto Reference:="R6C36"
    ActiveCell.Range("A1:B1").Select
    Selection.Copy
    ActiveCell.Range("A1:B" & Range("AA1")).Select
    ActiveSheet.Paste
    Application.CutCopyMode = False
    Calculate
    Selection.Copy
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
End Sub


Sub Macro36()

'clear all that is not ten games or more
    Application.Goto Reference:="R1C37"
    ActiveCell.Columns("A:A").EntireColumn.Select
    Selection.Find(What:="2_Clear", After:=ActiveCell, LookIn:=xlFormulas2, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False).Activate
    ActiveCell.Offset(0, -1).Range("A1").Select
    Application.CutCopyMode = False
    Selection.Copy
    ActiveCell.Offset(0, -8).Range("A1:J" & Range("aa1")).Select
    Application.CutCopyMode = False
    Selection.Clear
End Sub



Sub Macro38()
'shrink columns, and zoom to 75% for small laptops like mine
    Application.Goto Reference:="R1C1"
    Range(Selection, ActiveCell.SpecialCells(xlLastCell)).Select
    ActiveCell.Range("A1:AZ" & Range("aa1")).Select
    Selection.ColumnWidth = 0.5
    Selection.Columns.AutoFit
    ActiveWindow.Zoom = 75
    Selection.Columns.AutoFit
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,223,911
Messages
6,175,324
Members
452,635
Latest member
laura12345

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