''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