unspecified error & search for data within showed data in listbox based on textbox

abdelfattah

Well-known Member
Joined
May 3, 2019
Messages
1,429
Office Version
  1. 2019
  2. 2010
Platform
  1. 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

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
thanks
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result

Forum statistics

Threads
1,214,918
Messages
6,122,257
Members
449,075
Latest member
staticfluids

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top