Dear Sirs,
I am new to Excel VBA. I came across this video on YouTube, which describes a code for running a search in a Listbox for a keyword typed into a Textbox on the same Userform. The code seemed perfect for my project. But I found it throws up Run-Time Error 380 on line 7.
I give below the code I copied from the video and I have indicated where the error occurs.
I am using Excel 2013 on Windows 10.
Would you experts please help me. Thank you.
My code:
Private Sub TextBox1_AfterUpdate()
[INDENT]'Add Column Headers
With Me.ListBox1
.Clear
For ColHead = 1 To 6
.AddItem
.List(0, ColHead - 1) = Sheet1.Cells(1, ColHead).Value ? '<<< Run-Time Error 380, Invalid Property 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
LastRow = Sheet1.Range("A" & Rows.Count).End(xlUp).Row
For ShRow = 2 To LastRow
FindRow = Application.WorksheetFunction.CountIf(Sheet1.Rows(ShRow).EntireRow, FindVal)
If FindRow > 0 Then
For ListCol = 1 To 6
.AddItem
.List(ListRow, ListCol - 1) = Sheet1.Cells(ShRow, ListCol).Value
[INDENT][INDENT]Next ListCol
ListRow = ListRow + 1
End If
Next ShRow
End With
End Sub
Please forgive me if the indentations are not right in the above code. I am doing this for the first time. Thank you for your patience.
Bookmarks