Andrew1234
New Member
- Joined
- Feb 1, 2023
- Messages
- 29
- Office Version
- 2013
- Platform
- Windows
Hi all.
I have a table that is constantly being added to and i am trying to make a userform to search through the data. At present i think the search function working but i cannot get the table headers to become headers in my listbox. As the table is being added to frequently i have a dynamic range which is referenced in the Engine sheet.
here is the code i am using for the search function.
i have tried to add in
ListBox1.ColumnHeads = True
and then adjust the row number down one to compensate. but the headers will not populate text and unfortunatly i have a very limited understanding of vba.
here is also an image of the userform
As you can see the header bar is empty and the header is below. this is my issue.
As you can see i also have an issue as the list box is showing a huge number of empty rows. if there is a simple coding solution i would also be thankful.
many thanks to all in advance,
Andrew
I have a table that is constantly being added to and i am trying to make a userform to search through the data. At present i think the search function working but i cannot get the table headers to become headers in my listbox. As the table is being added to frequently i have a dynamic range which is referenced in the Engine sheet.
here is the code i am using for the search function.
VBA Code:
Private Sub TextBox1_Change()
With Me.ListBox1
.Clear
For ColHead = 2 To 9
.AddItem
.List(0, ColHead - 2) = Sheets("Product Data").Cells(18, ColHead).Value
Next ColHead
ListRow = 1
If IsDate(Me.TextBox1) Then
FindVal = CDate(Me.TextBox1)
ElseIf IsNumeric(Me.TextBox1) Then FindVal = Val(Me.TextBox1)
Else
FindVal = "*" & Me.TextBox1 & "*"
End If
ProductRng = Sheets("Engine").Range("B3").Value
LastRow = ProductRng + 18
For ShRow = 19 To LastRow
FindRow = Application.WorksheetFunction.CountIf(Sheets("Product Data").Rows(ShRow).EntireRow, "*" & FindVal & "*")
If FindRow > 0 Then
For ListCol = 2 To 9
.AddItem
.List(ListRow, ListCol - 2) = Sheets("Product Data").Cells(ShRow, ListCol).Value
Next ListCol
ListRow = ListRow + 1
End If
Next ShRow
End With
End Sub
i have tried to add in
ListBox1.ColumnHeads = True
and then adjust the row number down one to compensate. but the headers will not populate text and unfortunatly i have a very limited understanding of vba.
here is also an image of the userform
As you can see the header bar is empty and the header is below. this is my issue.
As you can see i also have an issue as the list box is showing a huge number of empty rows. if there is a simple coding solution i would also be thankful.
many thanks to all in advance,
Andrew
Last edited by a moderator: