Advertisement
Brovashift

Untitled

May 20th, 2023 (edited)
565
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Private racecardSheetName As String
  2. Private dataSheetName As String
  3. Private horseData As Object
  4. Dim originalData As Collection
  5.  
  6. Private Sub ComboBox1_Change()
  7.     Dim selectedValue As String
  8.     Dim item As Variant
  9.    
  10.     selectedValue = ComboBox1.value
  11.    
  12.     ' Preserve the "All" option in the ComboBox
  13.    If selectedValue = "All" Then
  14.         ' Clear existing items from ListView2
  15.        ListView2.ListItems.Clear
  16.        
  17.         ' Add all items from originalData to ListView2
  18.        For Each item In originalData
  19.             ListView2.ListItems.Add , , item.Text ' Add the item to ListView2
  20.            ' Add more subitems as needed
  21.        Next item
  22.     Else
  23.         ' Clear existing items from ListView2
  24.        ListView2.ListItems.Clear
  25.        
  26.         ' Filter the data based on the selected value
  27.        For Each item In originalData
  28.             If item.ListSubItems(4).Text = selectedValue Then
  29.                 ListView2.ListItems.Add , , item.Text ' Add the item to ListView2
  30.                ' Add more subitems as needed
  31.            End If
  32.         Next item
  33.     End If
  34. End Sub
  35.  
  36.  
  37.  
  38. Private Sub PopulateComboBox()
  39.  
  40.     ComboBox1.Clear
  41.     ComboBox1.AddItem "All" ' Add "All" value at the top
  42.    
  43.     Dim item As listItem
  44.     Dim columnValue As String
  45.     Dim itemExists As Boolean
  46.    
  47.     ' Assuming the column you want to extract values from is column 5 (index 4)
  48.    For Each item In ListView2.ListItems
  49.         columnValue = item.ListSubItems(4).Text
  50.        
  51.         ' Check if the value already exists in ComboBox
  52.        itemExists = False
  53.         For i = 0 To ComboBox1.ListCount - 1
  54.             If ComboBox1.List(i) = columnValue Then
  55.                 itemExists = True
  56.                 Exit For
  57.             End If
  58.         Next i
  59.        
  60.         ' Add the value to ComboBox if it doesn't exist
  61.        If Not itemExists Then
  62.             ComboBox1.AddItem columnValue
  63.         End If
  64.     Next item
  65. End Sub
  66.  
  67. Private Sub ListView1_BeforeLabelEdit(Cancel As Integer)
  68.     ' Check if the edit is being performed on the first column (index 1) of ListView1
  69.    If ListView1.ColumnHeaders(1).Index = 1 Then
  70.         ' Cancel the label edit event
  71.        Cancel = True
  72.     End If
  73. End Sub
  74.  
  75. Private Sub ListView2_BeforeLabelEdit(Cancel As Integer)
  76.     ' Check if the edit is being performed on the first column (index 1) of ListView2
  77.    If ListView2.ColumnHeaders(1).Index = 1 Then
  78.         ' Cancel the label edit event
  79.        Cancel = True
  80.     End If
  81. End Sub
  82.  
  83. Private Sub ListView1_ItemClick(ByVal item As MSComctlLib.listItem)
  84.  
  85.     PopulateComboBox
  86.     ' Get the horse name from the clicked item
  87.    Dim horseName As String
  88.     horseName = item.Text ' Assuming horse name is stored in the first column
  89.    
  90.     ' Populate child ListView with data from Sheet2
  91.    PopulateChildListView horseName
  92.  
  93. End Sub
  94.  
  95. Private Sub TreeView1_BeforeLabelEdit(Cancel As Integer)
  96.     On Error Resume Next
  97.    
  98.     ' Get the currently edited node
  99.    Dim editedNode As Node
  100.     Set editedNode = TreeView1.SelectedItem
  101.    
  102.     ' Check if the edited node is a parent or child node
  103.    If Err.Number <> 0 Then
  104.         ' Error occurred, cancel the label edit
  105.        Cancel = True
  106.     ElseIf editedNode.Child <> "" Or editedNode.Parent <> "" Then
  107.         ' Cancel the label edit
  108.        Cancel = True
  109.     End If
  110.    
  111.     On Error GoTo 0
  112. End Sub
  113.  
  114. Private Sub TreeView1_NodeClick(ByVal Node As MSComctlLib.Node)
  115.    
  116.     ' Clear existing items from parent ListView
  117.    ListView2.ListItems.Clear
  118.    
  119.     ' Declare variables
  120.    Dim raceCourse As String
  121.     Dim raceTime As String
  122.     Dim targetSheet As Worksheet
  123.     Dim targetRow As Long
  124.     Dim offTime As Date
  125.     Dim course As String
  126.     Dim raceName As String
  127.     Dim raceDate As Date
  128.     Dim prizeMoney As String
  129.     Dim formattedPrizeMoney As String
  130.     Dim regex As Object
  131.     Dim raceDist As String
  132.     Dim raceClass As String
  133.     Dim raceType As String
  134.     Dim going As String
  135.     Dim fieldSize As String
  136.    
  137.     ' Check if clicked node is a child node
  138.    If Not Node.Parent Is Nothing Then
  139.        
  140.         ' Get race course and race time from clicked nodes
  141.        raceCourse = Node.Parent.Text
  142.         raceTime = Node.Text
  143.        
  144.         ' Set target sheet
  145.        Set targetSheet = Worksheets(racecardSheetName)
  146.        
  147.         ' Find match in column B
  148.        On Error Resume Next
  149.         targetRow = targetSheet.Evaluate("match(timevalue(""" & raceTime & """),b:b,0)")
  150.         On Error GoTo 0
  151.        
  152.         If targetRow <> 0 Then
  153.            
  154.             ' Get race data from target row
  155.            offTime = targetSheet.Cells(targetRow, 2).value
  156.             course = targetSheet.Cells(targetRow, 3).value
  157.             raceName = targetSheet.Cells(targetRow, 4).value
  158.             raceDate = dateValue(targetSheet.Cells(targetRow, 1).value)
  159.             prizeMoney = targetSheet.Cells(targetRow, 10).value
  160.             raceDist = targetSheet.Cells(targetRow, 5).value
  161.             raceClass = targetSheet.Cells(targetRow, 6).value
  162.             raceType = targetSheet.Cells(targetRow, 7).value
  163.             going = targetSheet.Cells(targetRow, 9).value
  164.             fieldSize = targetSheet.Cells(targetRow, 8).value
  165.            
  166.             ' Create a regular expression object
  167.            Set regex = CreateObject("VBScript.RegExp")
  168.             With regex
  169.                 .Pattern = "\D" ' Match any non-digit character
  170.                .Global = True ' Match all occurrences
  171.            End With
  172.            
  173.             ' Remove non-numeric characters from prizeMoney
  174.            prizeMoney = regex.Replace(prizeMoney, "")
  175.             formattedPrizeMoney = "£" & Format(Val(prizeMoney), "#,##0")
  176.            
  177.             ' Display race data in labels
  178.            TimeLbl.Caption = Format(offTime, "h:mm")
  179.             CourseLbl.Caption = course
  180.             RaceNameLbl.Caption = raceName
  181.             DateLbl.Caption = Format(raceDate, "dd mmm yy")
  182.             prizeLbl.Caption = formattedPrizeMoney
  183.             distLbl.Caption = raceDist & "f"
  184.             classLbl.Caption = raceClass
  185.             raceTypeLbl = raceType
  186.             goingLbl = going
  187.             runnersLbl = fieldSize
  188.            
  189.            
  190.             ' Populate parent ListView with data from Sheet1
  191.            PopulateParentListView raceCourse, raceTime
  192.            
  193.            
  194.         Else
  195.             ' Display error message if no match was found
  196.            MsgBox "No race found for " & raceTime & " at " & raceCourse
  197.         End If
  198.  
  199.     End If
  200.    
  201. End Sub
  202. Private Sub PopulateParentListView(ByVal raceCourseName As String, ByVal raceTime As String)
  203.     ' Clear existing items from parent ListView
  204.    ListView1.ListItems.Clear
  205.    
  206.     ' Set the target sheet
  207.    Dim targetSheet As Worksheet
  208.     Set targetSheet = Worksheets(racecardSheetName)
  209.    
  210.     ' Create dictionary to store horse names and row numbers
  211.    'Dim horseData As Object
  212.    Set horseData = CreateObject("Scripting.Dictionary")
  213.    
  214.     ' Populate horse data dictionary based on raceCourseName and raceTime
  215.    Dim lastRow As Long
  216.     lastRow = targetSheet.Cells(targetSheet.Rows.Count, "A").End(xlUp).Row
  217.    
  218.     Dim i As Long
  219.     For i = 2 To lastRow
  220.         Dim key As String
  221.         key = raceCourseName & "_" & raceTime
  222.        
  223.         If Trim(targetSheet.Cells(i, 3).value) = Trim(raceCourseName) And Format(targetSheet.Cells(i, 2).value, "h:mm") = Format(timeValue(raceTime), "h:mm") Then
  224.             Dim horseName As String
  225.             horseName = targetSheet.Cells(i, 12).value
  226.            
  227.             ' Add horse name and row number to horse data dictionary
  228.            horseData(horseName) = i
  229.         End If
  230.     Next i
  231.    
  232.     ' Populate parent ListView using horse data dictionary
  233.    Dim horseNameKey As Variant
  234.     For Each horseNameKey In horseData.Keys
  235.         Dim rowIndex As Long
  236.         rowIndex = horseData(horseNameKey)
  237.        
  238.         Dim listItem As MSComctlLib.listItem
  239.         Set listItem = ListView1.ListItems.Add(, , horseNameKey) ' Column 1
  240.        
  241.         ' Add additional subitems
  242.        listItem.SubItems(1) = targetSheet.Cells(rowIndex, 28).value ' Column 2
  243.        listItem.SubItems(2) = targetSheet.Cells(rowIndex, 11).value ' Column 3
  244.        listItem.SubItems(3) = targetSheet.Cells(rowIndex, 22).value ' Column 4
  245.        listItem.SubItems(4) = targetSheet.Cells(rowIndex, 23).value ' Column 5
  246.        listItem.SubItems(5) = targetSheet.Cells(rowIndex, 24).value ' Column 6
  247.        listItem.SubItems(6) = targetSheet.Cells(rowIndex, 25).value ' Column 7
  248.        listItem.SubItems(7) = targetSheet.Cells(rowIndex, 26).value ' Column 8
  249.        listItem.SubItems(8) = targetSheet.Cells(rowIndex, 21).value ' Column 9
  250.        listItem.SubItems(9) = targetSheet.Cells(rowIndex, 27).value ' Column 10
  251.        listItem.SubItems(10) = targetSheet.Cells(rowIndex, 17).value ' Column 11
  252.        listItem.SubItems(11) = targetSheet.Cells(rowIndex, 19).value ' Column 12
  253.        ' Add more subitems as needed
  254.        
  255.         ' Additional settings optional data
  256.        listItem.SubItems(12) = targetSheet.Cells(rowIndex, 13).value ' Column 13
  257.        listItem.SubItems(13) = targetSheet.Cells(rowIndex, 15).value ' Column 14
  258.        listItem.SubItems(14) = targetSheet.Cells(rowIndex, 16).value ' Column 15
  259.        listItem.SubItems(15) = targetSheet.Cells(rowIndex, 18).value ' Column 16
  260.        listItem.SubItems(16) = targetSheet.Cells(rowIndex, 20).value ' Column 17
  261.        
  262.     Next horseNameKey
  263.    
  264.     PopulateChildListView horseData '************************************************************************************************
  265.    
  266. End Sub
  267. Sub PopulateChildListView(Optional ByVal horseName As Variant, Optional ByVal horseData As Object)
  268.     ' Clear existing items from child ListView
  269.    ListView2.ListItems.Clear
  270.    
  271.     ' Clear the originalData collection
  272.    Set originalData = New Collection
  273.    
  274.     ' Set the target sheet (Sheet2)
  275.    Dim targetSheet As Worksheet
  276.     Set targetSheet = Worksheets(dataSheetName) ' Replace "Sheet2" with the actual name of the sheet
  277.    
  278.     ' Find the last row in Sheet2
  279.    Dim lastRow As Long
  280.     lastRow = targetSheet.Cells(targetSheet.Rows.Count, "A").End(xlUp).Row
  281.    
  282.     ' Flag variable to indicate if any matching data is found
  283.    Dim matchFound As Boolean
  284.     matchFound = False
  285.    
  286.     If TypeName(horseName) = "String" Then
  287.         ' Loop through the rows in Sheet2 and populate the ChildListView with matching data
  288.        Dim i As Long
  289.         For i = 2 To lastRow ' Assuming the data starts from row 2
  290.            Dim horseNameSheet2 As String
  291.             horseNameSheet2 = targetSheet.Cells(i, 22).value ' Assuming the horse name is in the first column of Sheet2
  292.            
  293.             ' Remove the region letters from the horse name in Sheet2
  294.            Dim regionPos As Integer
  295.             regionPos = InStr(horseNameSheet2, "(")
  296.             If regionPos > 0 Then
  297.                 horseNameSheet2 = Trim(left(horseNameSheet2, regionPos - 1))
  298.             End If
  299.            
  300.             ' Compare the horse names
  301.            If StrComp(horseNameSheet2, horseName, vbTextCompare) = 0 Then
  302.                 Dim listItem As MSComctlLib.listItem
  303.                 Set listItem = ListView2.ListItems.Add(, , targetSheet.Cells(i, 1).value) ' Assuming the data you want to display is in the second column of Sheet2
  304.                
  305.                 ' Call the subroutine to add subitems
  306.                AddListViewSubItems listItem, targetSheet, i
  307.                
  308.                 ' Add the item to the originalData collection
  309.                originalData.Add listItem
  310.                
  311.                 matchFound = True ' Set the flag to indicate a match was found
  312.            End If
  313.         Next i
  314.     ElseIf TypeName(horseName) = "Dictionary" Then
  315.         ' Loop through the horse names in the dictionary and retrieve matching rows from Sheet2
  316.        Dim horseNameKey As Variant
  317.         For Each horseNameKey In horseName.Keys
  318.             Dim horseNameValue As String
  319.             horseNameValue = CStr(horseNameKey)
  320.            
  321.             ' Loop through the rows in Sheet2 and populate the ChildListView with matching data
  322.            Dim x As Long
  323.             For x = 2 To lastRow ' Assuming the data starts from row 2
  324.                Dim horseNameSheet22 As String
  325.                 horseNameSheet22 = targetSheet.Cells(x, 22).value ' Assuming the horse name is in the 22nd column of Sheet2
  326.                
  327.                 ' Remove the region letters from the horse name in Sheet2
  328.                Dim regionPos2 As Integer
  329.                 regionPos2 = InStr(horseNameSheet22, "(")
  330.                 If regionPos2 > 0 Then
  331.                     horseNameSheet22 = Trim(left(horseNameSheet22, regionPos2 - 1))
  332.                 End If
  333.                
  334.                 ' Compare the horse names
  335.                If StrComp(horseNameSheet22, horseNameValue, vbTextCompare) = 0 Then
  336.                     Dim listItem2 As MSComctlLib.listItem
  337.                     Set listItem2 = ListView2.ListItems.Add(, , targetSheet.Cells(x, 1).value) ' Assuming the data you want to display is in the first column of Sheet2
  338.                    
  339.                     ' Call the subroutine to add subitems
  340.                    AddListViewSubItems listItem2, targetSheet, x
  341.                    
  342.                      ' Add the item to the originalData collection
  343.                    originalData.Add listItem2
  344.                    
  345.                     matchFound = True ' Set the flag to indicate a match was found
  346.                End If
  347.             Next x
  348.         Next horseNameKey
  349.     End If
  350.    
  351.     ' Check if any matching data was found for the horse name(s)
  352.    If Not matchFound Then
  353.         MsgBox "No matching data found for horse name: " & horseName
  354.     End If
  355.    
  356.     PopulateComboBox
  357.    
  358. End Sub
  359.  
  360. Private Sub AddListViewSubItems(ByVal listItem As MSComctlLib.listItem, ByVal targetSheet As Worksheet, ByVal i As Long)
  361.     ' Add subitems to the ListView2
  362.  
  363.     listItem.SubItems(1) = targetSheet.Cells(i, 22).value ' Column 1
  364.    listItem.SubItems(2) = targetSheet.Cells(i, 3).value ' Column 2
  365.    listItem.SubItems(3) = targetSheet.Cells(i, 5).value ' Column 3
  366.    listItem.SubItems(4) = targetSheet.Cells(i, 13).value ' Column 4
  367.    listItem.SubItems(5) = targetSheet.Cells(i, 15).value ' Column 5
  368.  
  369.     Dim unformattedTime As String
  370.     unformattedTime = targetSheet.Cells(i, 27).Text ' Assuming the time value is stored as text in the cell
  371.  
  372.     ' Assign the unformatted time to the SubItems property
  373.    listItem.SubItems(6) = unformattedTime ' Column 7
  374.  
  375.     listItem.SubItems(7) = targetSheet.Cells(i, 18).value ' Column 8
  376.    listItem.SubItems(8) = targetSheet.Cells(i, 16).value ' Column 9
  377.    listItem.SubItems(9) = targetSheet.Cells(i, 21).value ' Column 10
  378.    listItem.SubItems(10) = targetSheet.Cells(i, 7).value ' Column 12
  379.    listItem.SubItems(11) = targetSheet.Cells(i, 25).value ' Column 13
  380.    listItem.SubItems(12) = targetSheet.Cells(i, 33).value ' Column 14
  381.    listItem.SubItems(13) = targetSheet.Cells(i, 34).value ' Column 15
  382.    listItem.SubItems(14) = targetSheet.Cells(i, 26).value ' Column 16
  383.    listItem.SubItems(15) = targetSheet.Cells(i, 19).value ' Column 17
  384.    listItem.SubItems(16) = targetSheet.Cells(i, 17).value ' Column 18
  385.    listItem.SubItems(17) = targetSheet.Cells(i, 30).value ' Column 19
  386.    listItem.SubItems(18) = targetSheet.Cells(i, 32).value ' Column 20
  387.    listItem.SubItems(19) = targetSheet.Cells(i, 39).value ' Column 3
  388.    ' Add more subitems as needed
  389.    
  390.    
  391.    
  392. End Sub
  393.  
  394.  
  395. Private Sub CreateListView1ColumnHeaders()
  396.  
  397.     ' Add column headers
  398.    ListView1.ColumnHeaders.Clear
  399.     ListView1.ColumnHeaders.Add , , "Horse Name" ' Column 1
  400.    ListView1.ColumnHeaders.Add , , "Form" ' Column 2
  401.    ListView1.ColumnHeaders.Add , , "Age" ' Column 3
  402.    ListView1.ColumnHeaders.Add , , "HG" ' Column 4
  403.    ListView1.ColumnHeaders.Add , , "WGT" ' Column 5
  404.    ListView1.ColumnHeaders.Add , , "OR" ' Column 6
  405.    ListView1.ColumnHeaders.Add , , "RPR" ' Column 7
  406.    ListView1.ColumnHeaders.Add , , "TS" ' Column 8
  407.    ListView1.ColumnHeaders.Add , , "Draw" ' Column 9
  408.    ListView1.ColumnHeaders.Add , , "Jockey" ' Column 10
  409.    ListView1.ColumnHeaders.Add , , "Trainer" ' Column 11
  410.    ListView1.ColumnHeaders.Add , , "Comments" ' Column 12
  411.    ' Add more column headers as needed
  412.    
  413.     'Optional settings columns
  414.    ListView1.ColumnHeaders.Add , , "Sex" ' Column 13
  415.    ListView1.ColumnHeaders.Add , , "Dam" ' Column 14
  416.    ListView1.ColumnHeaders.Add , , "Sire" ' Column 15
  417.    ListView1.ColumnHeaders.Add , , "Owner" ' Column 16
  418.    ListView1.ColumnHeaders.Add , , "Spotlight" ' Column 17
  419.    
  420.     Me.ListView1.Gridlines = True
  421.  
  422. End Sub
  423.  
  424. Private Sub CreateListView2ColumnHeaders()
  425.    
  426.     ' Add column headers*******************************************************************************
  427.    ListView2.ColumnHeaders.Clear
  428.     ListView2.ColumnHeaders.Add , , "Date" ' Column 1
  429.    ListView2.ColumnHeaders.Add , , "Name" ' Column 2
  430.    ListView2.ColumnHeaders.Add , , "Course" ' Column 3
  431.    ListView2.ColumnHeaders.Add , , "Race Type" ' Column 4
  432.    ListView2.ColumnHeaders.Add , , "Distance" ' Column 5
  433.    ListView2.ColumnHeaders.Add , , "Going" ' Column 6
  434.    ListView2.ColumnHeaders.Add , , "Time" ' Column 7
  435.    ListView2.ColumnHeaders.Add , , "Position" ' Column 8
  436.    ListView2.ColumnHeaders.Add , , "Runners" ' Column 9
  437.    ListView2.ColumnHeaders.Add , , "BTN" ' Column 10
  438.    ListView2.ColumnHeaders.Add , , "Class" ' Column 11
  439.    ListView2.ColumnHeaders.Add , , "WGT" ' Column 12
  440.    ListView2.ColumnHeaders.Add , , "OR" ' Column 13
  441.    ListView2.ColumnHeaders.Add , , "RPR" ' Column 14
  442.    ListView2.ColumnHeaders.Add , , "HG" ' Column 15
  443.    ListView2.ColumnHeaders.Add , , "Draw" ' Column 16
  444.    ListView2.ColumnHeaders.Add , , "No." ' Column 17
  445.    ListView2.ColumnHeaders.Add , , "Jockey" ' Column 18
  446.    ListView2.ColumnHeaders.Add , , "Prize" ' Column 19
  447.    ListView2.ColumnHeaders.Add , , "Comments" ' Column 20
  448.    
  449.     Me.ListView1.Gridlines = True
  450. End Sub
  451. Private Sub UserForm_Initialize()
  452.     ' Import racecard CSV data into a new sheet
  453.    Dim newSheet As Worksheet
  454.     Set newSheet = Workbooks("RaceCardAnalyser.xlsm").Worksheets.Add
  455.     With newSheet.QueryTables.Add(Connection:= _
  456.         "TEXT;D:\Racecard Analysis Project\Racecards\racecards.csv", Destination:=newSheet.Range("A1"))
  457.         .TextFileCommaDelimiter = True 'Set delimiter to comma
  458.        .TextFileParseType = xlDelimited
  459.         .Refresh
  460.     End With
  461.    
  462.     ' Import historical data CSV data into a new sheet
  463.    Dim newSheet2 As Worksheet
  464.     Set newSheet2 = Workbooks("RaceCardAnalyser.xlsm").Worksheets.Add
  465.     With newSheet2.QueryTables.Add(Connection:= _
  466.         "TEXT;D:\Racecard Analysis Project\Data\data.csv", Destination:=newSheet2.Range("A1"))
  467.         .TextFileCommaDelimiter = True 'Set delimiter to comma
  468.        .TextFileParseType = xlDelimited
  469.         .Refresh
  470.     End With
  471.    
  472.     CreateListView1ColumnHeaders
  473.     CreateListView2ColumnHeaders
  474.    
  475.     ' Store the name of the new racecard sheet
  476.    racecardSheetName = newSheet.Name
  477.    
  478.     ' Store the name of the new data sheet
  479.    dataSheetName = newSheet2.Name
  480.    
  481.     ' Create dictionary to store racecourses and times
  482.    Dim raceData As Object
  483.     Set raceData = CreateObject("Scripting.Dictionary")
  484.    
  485.     ' Loop through all rows of data
  486.    Dim currRow As Long
  487.     For currRow = 2 To newSheet.Cells(newSheet.Rows.Count, "A").End(xlUp).Row
  488.         ' Get current race course and race time AND horse name
  489.        Dim raceCourse As String
  490.         Dim raceTime As String
  491.         Dim horseName As String
  492.        
  493.         raceCourse = newSheet.Cells(currRow, 3).value
  494.         raceTime = Format(newSheet.Cells(currRow, 2).value, "h:mm")
  495.         horseName = newSheet.Cells(currRow, 12).value
  496.        
  497.         ' Add race course and race time to dictionary AND horse name
  498.        If Not raceData.Exists(raceCourse) Then
  499.             raceData.Add raceCourse, New Collection
  500.         End If
  501.        
  502.         ' Add race time to collection if it doesn't already exist
  503.        Dim raceTimeCheck As Collection
  504.         Set raceTimeCheck = raceData(raceCourse)
  505.         Dim found As Boolean
  506.         found = False
  507.         Dim i As Long
  508.         For i = 1 To raceTimeCheck.Count
  509.             If raceTimeCheck(i) = raceTime Then
  510.                 found = True
  511.                 Exit For
  512.             ElseIf raceTimeCheck(i) > raceTime Then
  513.                 raceTimeCheck.Add raceTime, Before:=i
  514.                 found = True
  515.                 Exit For
  516.             End If
  517.         Next i
  518.         If Not found Then
  519.             raceTimeCheck.Add raceTime
  520.         End If
  521.        
  522.     Next currRow
  523.    
  524.     ' Populate TreeView with data from dictionary
  525.    Dim raceCourses As Variant
  526.     For Each raceCourses In raceData
  527.         ' Add parent node for race course
  528.        Dim currNode As Node
  529.         Set currNode = TreeView1.Nodes.Add(, , raceCourses, raceCourses)
  530.         currNode.Tag = raceCourses
  531.        
  532.         ' Add child nodes for race times
  533.        Dim raceTimes As Variant
  534.         For Each raceTimes In raceData(raceCourses)
  535.             Set currNode = TreeView1.Nodes.Add(raceCourses, tvwChild, , raceTimes)
  536.             currNode.Tag = raceTimes
  537.         Next raceTimes
  538.     Next raceCourses
  539.    
  540.     ' Clean up
  541.    Set newSheet = Nothing
  542.     Set raceData = Nothing
  543.    
  544. End Sub
  545.  
  546. Private Sub UserForm_Terminate()
  547.  
  548.     ' NOTES: Remove the sheet created when the form was initialized
  549.    Application.DisplayAlerts = False 'Suppress alert message
  550.    Workbooks("RaceCardAnalyser.xlsm").Sheets(racecardSheetName).Delete
  551.    
  552.     Workbooks("RaceCardAnalyser.xlsm").Sheets(dataSheetName).Delete
  553.     Application.DisplayAlerts = True
  554.    
  555. End Sub
  556.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement