Search by textbox and criteria combobox and show in listbox

mredvard

Banned user
Joined
Nov 17, 2023
Messages
7
Hello, good day everyone, I want to search based on the combobox as (search column) and textbox in sheet 1.
How is this possible?


search by combo box.xlsm
ABCDEFGH
1no.Nameidsexagedate of birthIQ TestMeaning of Name
214Ani4935426663female2231/10/199998Ornament, Beautiful, Variant of Anne / Ane
315Anna4037366181female2026/10/2001126‘Grace’. Also used as a nickname for Annabelle
416Anya9330871997female2512/04/1997109Inexhaustible, Gracious, Graceful
517Ariel3660975387female2527/01/1997127‘Lion of God’. It is also spelt as Arielle.
618Arya9935838857female2317/07/1999108‘Lioness, Noble’. It is frequently spelt as Aria.
719Ash3882405562female2514/12/199696Form of Ashley, Ash Tree Meadow
820Ashley7564224317female2603/03/199699‘One who lives in the ash tree grove’. It is one of the modern English baby girl names.
921Audrey4121552927female1804/11/2003111Strength
1022Ava6560141181female1929/10/2002124‘Bird’ or ‘the living one’ or ‘life’. It may also be spelt as Eva.
1123Badra8004003618female2710/05/1995114Full Moon, Pretty, Goddess Durga
1224Beatrice6870820925female2011/02/200291‘She who makes you happy’. It is also spelt Beatrix.
1325Belinda3658130608female2409/06/1998119‘Beautiful’. One of its other variants is ‘Bella’. ‘Bright linden tree’ or ‘bright serpent’.
1426Bella2725479507female1820/09/2003122‘Beautiful’. It is often used as a nickname for other names ending in –bella, like Annabella, Arabella, etc.
1527Bency5191837585female2606/04/1996111Right Hand of Jesus Christ, A Talkative Girl who is Very Scared
1628Berey4061161891female2012/05/2002107Exalted One, Bearer of Victory, True Image, To Help, Berry
1729Bery1556003492female2214/12/1999129True Image, Bearer of Victory, Berry, To Help, Exalted One
1830Bety2871809184female2001/09/2002119God is My Oath, God is Perfection
1931Bitsy2218154671female2217/11/1999109God is Perfection, God is My Oath
2032Brianna5026781508female2120/08/2001123‘Strong’
sheet1
 

Attachments

  • search form.png
    search form.png
    6.5 KB · Views: 31
  • sh1.png
    sh1.png
    65.3 KB · Views: 33
it will be in the whole columns

Try this:

VBA Code:
Option Explicit

Dim a As Variant

Private Sub Combobox1_change()
  Call FilterData
End Sub

Private Sub TextBox1_Change()
  Call FilterData
End Sub

Sub FilterData()
  Dim cmb As String, txt As String
  Dim b As Variant
  Dim i As Long, j As Long, k As Long, col As Long, m As Long
 
  ReDim b(1 To UBound(a, 1), 1 To UBound(a, 2))
  ListBox1.Clear
  
  If ComboBox1.ListIndex = -1 Then
    col = 0
  Else
    col = ComboBox1.ListIndex + 1
  End If
  
  If TextBox1.Value = "" Then Exit Sub
  
  
  For i = 1 To UBound(a)
    
    If col = 0 Then
      For m = 1 To UBound(a, 2)
        If LCase(a(i, m)) Like "*" & LCase(TextBox1.Value) & "*" Then
          k = k + 1
          For j = 1 To 8
            b(k, j) = a(i, j)
          Next
          Exit For
        End If
      Next
  
    Else
    
      txt = TextBox1.Value
      If LCase(a(i, col)) Like "*" & LCase(TextBox1.Value) & "*" Then
        k = k + 1
        For j = 1 To 8
          b(k, j) = a(i, j)
        Next
      End If
    
    End If
  Next i
  If k > 0 Then ListBox1.List = b
End Sub

Private Sub userform_initialize()
  Dim ws As Worksheet
  
  Set ws = ThisWorkbook.Sheets("sheet1")
  ComboBox1.List = Application.Transpose(ws.Range("A1:H1").Value)
  ListBox1.ColumnCount = 8
  a = ws.Range("A2:H" & ws.Range("A" & Rows.Count).End(xlUp).Row).Value
End Sub

🫡
 
Upvote 1

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"

Forum statistics

Threads
1,224,813
Messages
6,181,115
Members
453,021
Latest member
Justyna P

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