abdelfattah
Well-known Member
- Joined
- May 3, 2019
- Messages
- 1,429
- Office Version
- 2019
- 2010
- Platform
- Windows
I need help to fixing this error
when I run the userform shows data based on last entered date and when I try searching for item based on column B by using textbox will populate unspecified error in this line
and if it's possible reintroduce the code by array to make decreasing code slowness if the data are huge.
this is what I have
thanks
when I run the userform shows data based on last entered date and when I try searching for item based on column B by using textbox will populate unspecified error in this line
VBA Code:
Me.ListBox1.Clear
and if it's possible reintroduce the code by array to make decreasing code slowness if the data are huge.
this is what I have
VBA Code:
Private Sub TextBox1_Change()
Me.TextBox1.Text = StrConv(Me.TextBox1.Text, vbUpperCase)
Dim i, x As Long
Me.ListBox1.Clear
On Error Resume Next
For i = 2 To Application.WorksheetFunction.CountA(sheet1.Range("B:B"))
a = Len(Me.TextBox1.Text)
For x = 1 To 6
If Left(sheet1.Cells(i, x).Text, a) = Left(Me.TextBox1.Text, a) Then
Me.ListBox1.AddItem sheet1.Cells(i, 1).Value
Me.ListBox1.List(ListBox1.ListCount - 1, 1) = sheet1.Cells(i, 2).Value
Me.ListBox1.List(ListBox1.ListCount - 1, 2) = sheet1.Cells(i, 3).Value
Me.ListBox1.List(ListBox1.ListCount - 1, 3) = sheet1.Cells(i, 4).Value
Me.ListBox1.List(ListBox1.ListCount - 1, 4) = sheet1.Cells(i, 5).Value
Me.ListBox1.List(ListBox1.ListCount - 1, 5) = sheet1.Cells(i, 6).Value
End If
Next
Next i
End Sub
Private Sub UserForm_Initialize()
Dim LastRow As Long
LastRow = Range("A" & Rows.Count).End(xlUp).Row
Dim MaxDt, CntLatestDate As Long
MaxDt = WorksheetFunction.Max(Range("A:A"))
CntLatestDt = Application.WorksheetFunction.CountIf(Range("A:A"), MaxDt)
With ListBox1
.ColumnCount = 6
.ColumnWidths = "80;80;120;80;60;60"
.RowSource = ("A" & LastRow - CntLatestDt + 1) & ":F" & LastRow
End With
End Sub