Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Private Sub PopulateChildListView(horseName As String)
- ' Clear existing items from parent ListView
- ListView2.ListItems.Clear
- ' Set the target sheet (Sheet2)
- Dim targetSheet As Worksheet
- Set targetSheet = Worksheets(dataSheetName) ' Replace "Sheet2" with the actual name of the sheet
- ' Find the last row in Sheet2
- Dim lastRow As Long
- lastRow = targetSheet.Cells(targetSheet.Rows.Count, "A").End(xlUp).Row
- ' Flag variable to indicate if any matching data is found
- Dim matchFound As Boolean
- matchFound = False
- ' Loop through the rows in Sheet2 and populate the ChildListView with matching data
- Dim i As Long
- For i = 2 To lastRow ' Assuming the data starts from row 2
- Dim horseNameSheet2 As String
- horseNameSheet2 = targetSheet.Cells(i, 22).Value ' Assuming the horse name is in the first column of Sheet2
- ' Remove the region letters from the horse name in Sheet2
- Dim regionPos As Integer
- regionPos = InStr(horseNameSheet2, "(")
- If regionPos > 0 Then
- horseNameSheet2 = Trim(left(horseNameSheet2, regionPos - 1))
- End If
- ' Compare the horse names
- If StrComp(horseNameSheet2, horseName, vbTextCompare) = 0 Then
- Dim listItem As MSComctlLib.listItem
- Set listItem = ListView2.ListItems.Add(, , targetSheet.Cells(i, 1).Value) ' Assuming the data you want to display is in the second column of Sheet2
- ' Add additional subitems if needed
- listItem.SubItems(1) = targetSheet.Cells(i, 22).Value ' Column 2
- listItem.SubItems(2) = targetSheet.Cells(i, 3).Value ' Column 3
- listItem.SubItems(3) = targetSheet.Cells(i, 5).Value ' Column 4
- listItem.SubItems(4) = targetSheet.Cells(i, 13).Value ' Column 5
- listItem.SubItems(5) = targetSheet.Cells(i, 15).Value ' Column 6
- Dim unformattedTime As String
- unformattedTime = targetSheet.Cells(i, 27).Text ' Assuming the time value is stored as text in the cell
- ' Assign the unformatted time to the SubItems property
- listItem.SubItems(6) = unformattedTime ' Column 7
- listItem.SubItems(7) = targetSheet.Cells(i, 18).Value ' Column 8
- listItem.SubItems(8) = targetSheet.Cells(i, 16).Value ' Column 9
- listItem.SubItems(9) = targetSheet.Cells(i, 21).Value ' Column 10
- listItem.SubItems(10) = targetSheet.Cells(i, 7).Value ' Column 12
- listItem.SubItems(11) = targetSheet.Cells(i, 25).Value ' Column 13
- listItem.SubItems(12) = targetSheet.Cells(i, 33).Value ' Column 14
- listItem.SubItems(13) = targetSheet.Cells(i, 34).Value ' Column 15
- listItem.SubItems(14) = targetSheet.Cells(i, 26).Value ' Column 16
- listItem.SubItems(15) = targetSheet.Cells(i, 19).Value ' Column 17
- listItem.SubItems(16) = targetSheet.Cells(i, 17).Value ' Column 18
- listItem.SubItems(17) = targetSheet.Cells(i, 30).Value ' Column 19
- listItem.SubItems(18) = targetSheet.Cells(i, 32).Value ' Column 20
- listItem.SubItems(19) = targetSheet.Cells(i, 39).Value ' Column 3
- matchFound = True ' Set the flag to indicate a match was found
- End If
- Next i
- ' Check if any matching data was found
- If Not matchFound Then
- MsgBox "No matching data found for horse name: " & horseName, vbInformation
- ' Clear existing items from parent ListView
- ListView2.ListItems.Clear
- End If
- End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement