[VBA] [UserForm] Search Data by TextBoxes then show result in listbox

zeromax1

Board Regular
Joined
Mar 20, 2020
Messages
52
Office Version
  1. 365
Platform
  1. Windows
Hi Expert,

I found a VBA code that can show the data in Listbox when I type the data in textbox1. However, I have more than 1 dependable Textboxes. Just like the below screen:

1614510435317.png


Below are the codes:

VBA Code:
Private Sub txtpol_Change()

Dim ws As Worksheet
Dim i, LR As Long

Set ws = ThisWorkbook.Worksheets(1)

LR = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row


Me.txtpol = Format(StrConv(Me.txtpol, vbLowerCase))
Me.ListBox1.Clear

Me.ListBox1.AddItem "Title1"

Me.ListBox1.List(0, 1) = "Title2"
Me.ListBox1.List(0, 2) = "Title3"
Me.ListBox1.List(0, 3) = "Title4"
Me.ListBox1.List(0, 4) = "Title5"
Me.ListBox1.List(0, 5) = "Title6"
Me.ListBox1.List(0, 6) = "Title7"

Me.ListBox1.Selected(0) = True

For i = 11 To LR

    For x = 1 To Len(ws.Cells(i, 1))
    a = Me.txtbox1.TextLength
        If LCase(Mid(ws.Cells(i, 1), x, a)) = Me.txtbox1 And Me.txtbox1 <> "" Then
             Me.ListBox1.AddItem ws.Cells(i, 1)
             Me.ListBox1.List(ListBox1.ListCount - 1, 1) = ws.Cells(i, 2)
             Me.ListBox1.List(ListBox1.ListCount - 1, 2) = ws.Cells(i, 3)
             Me.ListBox1.List(ListBox1.ListCount - 1, 3) = ws.Cells(i, 4)
             Me.ListBox1.List(ListBox1.ListCount - 1, 4) = ws.Cells(i, 5)
             Me.ListBox1.List(ListBox1.ListCount - 1, 5) = ws.Cells(i, 6)
             Me.ListBox1.List(ListBox1.ListCount - 1, 6) = ws.Cells(i, 7)
             
    
        End If

    Next x

Next i


End Sub


Below are the data worksheet:

Title1Title2Title3Title4Title5Title6Title7
HKKWCXXX$ 1,087.00$ 3,828.00$ 5,143.00$ 8,335.00
CNBJKHXX$ 6,698.00$ 2,208.00$ 6,838.00$ 1,275.00
USWSCXXX$ 1,947.00$ 1,148.00$ 2,000.00$ 6,607.00
AUBACOXX$ 6,150.00$ 6,448.00$ 8,299.00$ 5,216.00
ADCDABCC$ 9,518.00$ 7,224.00$ 7,337.00$ 7,955.00
AZEFCXXX$ 6,854.00$ 5,779.00$ 9,959.00$ 3,954.00
AIGHKHXX$ 3,250.00$ 6,113.00$ 5,750.00$ 4,814.00
FRDKCXXX$ 7,210.00$ 3,139.00$ 4,598.00$ 5,273.00
BRDGCOXX$ 8,037.00$ 2,884.00$ 5,721.00$ 2,388.00
BVDDABCC$ 7,114.00$ 4,512.00$ 7,394.00$ 8,134.00
CVADCXXX$ 890.00$ 1,467.00$ 945.00$ 7,420.00
KHCIKHXX$ 3,960.00$ 8,218.00$ 4,893.00$ 3,633.00
CMCICXXX$ 6,005.00$ 6,314.00$ 9,405.00$ 9,527.00
CAADCOXX$ 3,517.00$ 6,655.00$ 8,604.00$ 9,522.00
CXGHABCC$ 1,087.00$ 3,828.00$ 5,143.00$ 8,335.00
CDBACXXX$ 1,087.00$ 3,828.00$ 5,143.00$ 8,335.00
HKBAKHXX$ 1,087.00$ 3,828.00$ 5,143.00$ 8,335.00
CGCDCXXX$ 1,087.00$ 3,828.00$ 5,143.00$ 8,335.00
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.

Forum statistics

Threads
1,214,975
Messages
6,122,537
Members
449,088
Latest member
RandomExceller01

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