Advertisement
Combreal

GTOTM.vba

Feb 19th, 2021
1,688
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Sub GTOTM()
  2.     Call GetLogs
  3.     Dim Team As String
  4.     Dim Team1D() As Variant
  5.     Dim TeamRep() As Variant
  6.     Dim size As Integer
  7.    
  8.     For j = LBound(samLogs) To TotalRows - 1
  9.         If InStr(samLogs(1, j), "2021") Then
  10.             Team = samLogs(7, j)
  11.             If IsArrayAllocated(Team1D) Then
  12.                 If IsInArray(Team, Team1D) Then
  13.                     For h = LBound(Team1D) To UBound(Team1D)
  14.                         If Team1D(h) = Team Then
  15.                             TeamRep(h) = TeamRep(h) + 1
  16.                         End If
  17.                     Next h
  18.                 Else
  19.                     size = size + 1
  20.                     ReDim Preserve Team1D(size)
  21.                     ReDim Preserve TeamRep(size)
  22.                     Team1D(size - 1) = Team
  23.                     TeamRep(size - 1) = 1
  24.                 End If
  25.             Else
  26.                 size = 1
  27.                 ReDim Team1D(size)
  28.                 ReDim TeamRep(size)
  29.                 Team1D(0) = Team
  30.                 TeamRep(0) = 1
  31.             End If
  32.         End If
  33.     Next j
  34.    
  35.     For i = LBound(Team1D) To UBound(Team1D)
  36.         'Debug.Print Team1D(i) & "  " & TeamRep(i)
  37.        If TeamRep(i) = WorksheetFunction.Max(TeamRep) Then
  38.             Debug.Print Team1D(i)
  39.         End If
  40.     Next i
  41. End Sub
  42.            
  43. Function IsArrayAllocated(Arr As Variant) As Boolean
  44.     On Error Resume Next
  45.     IsArrayAllocated = IsArray(Arr) And Not IsError(LBound(Arr, 1)) And LBound(Arr, 1) <= UBound(Arr, 1)
  46. End Function
  47.  
  48. Function IsInArray(stringToBeFound As String, Arr As Variant) As Boolean
  49.     For i = LBound(Arr) To UBound(Arr)
  50.         If Arr(i) = stringToBeFound Then
  51.             IsInArray = True
  52.             Exit Function
  53.         End If
  54.     Next i
  55.     IsInArray = False
  56. End Function
  57.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement