campbell1093
New Member
- Joined
- Aug 27, 2024
- Messages
- 6
- Office Version
- 365
- Platform
- Windows
New poster, so I apologize if this has been answered elsewhere.
I've been working on a tracker for work, where I have 10 columns and (right now) 35 rows. It's been an ongoing project for several months, and I've gone through several iterations.
In my workbook, I have a search userform and an entry userform. The entry form works perfectly, except I'm trying to get it to detect the date for when the event occurs and select the correct month tab. The search function has worked flawlessly up until my last update and allows me to search all data from all tabs, but my last update didn't change any of the code pertaining to the search feature. Now, I get a "run time error '13' type mismatch" whenever I enter a single character into my search userform.
I'm about to my wits end with this, as I've tried copying the working code from the previous version, I've tried importing the whole userform as is, and I've tried commenting out some other code I've since added.
For reference, I use the following code:
The error in debug will highlight "For x = 1 To Len(sh.Cells(i, 2))", but again, all my previous versions with the same code have not errored.
Attached are the links for the versions I've been working with. Any help is greatly appreciated!
I've been working on a tracker for work, where I have 10 columns and (right now) 35 rows. It's been an ongoing project for several months, and I've gone through several iterations.
In my workbook, I have a search userform and an entry userform. The entry form works perfectly, except I'm trying to get it to detect the date for when the event occurs and select the correct month tab. The search function has worked flawlessly up until my last update and allows me to search all data from all tabs, but my last update didn't change any of the code pertaining to the search feature. Now, I get a "run time error '13' type mismatch" whenever I enter a single character into my search userform.
I'm about to my wits end with this, as I've tried copying the working code from the previous version, I've tried importing the whole userform as is, and I've tried commenting out some other code I've since added.
For reference, I use the following code:
Excel Formula:
Private Sub TextBox1_Change()
Set sh = Sheets("Data")
Dim i As Long
Dim x As Long
Dim p As Long
Me.ListBox1.Clear
Me.ListBox1.AddItem "Case"
Me.ListBox1.List(ListBox1.ListCount - 1, 1) = "Complainant"
Me.ListBox1.List(ListBox1.ListCount - 1, 2) = "Offense"
Me.ListBox1.List(ListBox1.ListCount - 1, 3) = "Level"
Me.ListBox1.List(ListBox1.ListCount - 1, 4) = "Reported"
Me.ListBox1.List(ListBox1.ListCount - 1, 5) = "Suspect"
Me.ListBox1.List(ListBox1.ListCount - 1, 6) = "Disposition"
Me.ListBox1.List(ListBox1.ListCount - 1, 7) = "Assigned"
Me.ListBox1.List(ListBox1.ListCount - 1, 8) = "Action"
Me.ListBox1.List(ListBox1.ListCount - 1, 9) = "As Of"
SearchData.ListBox1.ColumnWidths = "50;90;120;30;45;120;80;50;85;50"
'width "case;victim;offense;level;reported;suspect;disposition;assignment date;actions;as of date"
Me.ListBox1.Selected(0) = True
For i = 2 To sh.Range("A" & Rows.Count).End(xlUp).Row
[COLOR=rgb(250, 197, 28)]For x = 1 To Len(sh.Cells(i, 2))[/COLOR]
p = Me.TextBox1.TextLength
If LCase(Mid(sh.Cells(i, 1), x, p)) = Me.TextBox1 And Me.TextBox1 <> "" Or _
LCase(Mid(sh.Cells(i, 2), x, p)) = Me.TextBox1 And Me.TextBox1 <> "" Or _
LCase(Mid(sh.Cells(i, 6), x, p)) = Me.TextBox1 And Me.TextBox1 <> "" Then
With Me.ListBox1
.AddItem sh.Cells(i, 1)
.List(ListBox1.ListCount - 1, 1) = sh.Cells(i, 2)
.List(ListBox1.ListCount - 1, 2) = sh.Cells(i, 3)
.List(ListBox1.ListCount - 1, 3) = sh.Cells(i, 4)
.List(ListBox1.ListCount - 1, 4) = sh.Cells(i, 5)
.List(ListBox1.ListCount - 1, 5) = sh.Cells(i, 6)
.List(ListBox1.ListCount - 1, 6) = sh.Cells(i, 7)
.List(ListBox1.ListCount - 1, 7) = sh.Cells(i, 8)
.List(ListBox1.ListCount - 1, 8) = sh.Cells(i, 9)
.List(ListBox1.ListCount - 1, 9) = sh.Cells(i, 10)
End With
End If
Next x
Next i
End Sub
The error in debug will highlight "For x = 1 To Len(sh.Cells(i, 2))", but again, all my previous versions with the same code have not errored.
Attached are the links for the versions I've been working with. Any help is greatly appreciated!