Searchable combobox value to populate listbox1

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
5,699
Office Version
  1. 2007
Platform
  1. Windows
I have a worksheet for which i would like the code to look in column I for a searchable value & then take values from various cells on that same row & place into a listbox.
Searchable values will be in a Combobox.
First row to search is 6 then down the page.

So it should work like so,

Select the searchable value from the Combobox, at present these will be as follows, These will be part of the ADD ITEM to populate Combobox once userform is open & i can add to it as i go along.
AUTEL IM 508
HANDY BABY
SKP 900

Press the command button to start the search.
The values to populate the lictbox will always be in columns A D F G
It is only the values in the combobox drop down that will be different

So example for searching AUTEL IM 508
First instance of AUTEL IM 508 is in row 22, so collect val;ue from thats rows cells A D F G & place in ListBox1.
Code continues to run.
Second instance of AUTEL IM 508 is in row 39, so collect val;ue from thats rows cells A D F G & place in ListBox1.
Etc Etc until no more values in column I are found so then MsgBox SEARCH NOW COMPLETE

Many thanks
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Having a go but i know its incorrect.
So please advise.
Add Item works but running search i get i not defined

Rich (BB code):
Private Sub SearchForm_Click()
  Dim R As Range, f As Range, cell As String, added As Boolean
  Dim sh As Worksheet
  
  Set sh = Sheets("DATABASE")
  sh.Select
  With ListBox1
    .Clear
    .ColumnCount = 4
    .ColumnWidths = "210;260;150;10"
    If ComboBox1.Value = "" Then Exit Sub
    Set R = Range("I6", Range("I" & Rows.Count).End(xlUp))
    Set f = R.Find(ComboBox1.Value, LookIn:=xlValues, LookAt:=xlWhole)
    If Not f Is Nothing Then
      cell = f.Address
      Do
        added = False
        For i = 0 To .ListCount - 1
          Select Case StrComp(.List(i), f.Value, vbTextCompare)
            Case 0, 1
              .AddItem f.Value, i
              .List(i, 1) = f.Offset(, -8).Value
              .List(i, 2) = f.Offset(, -5).Value
              .List(i, 3) = f.Offset(, -3).Value
              added = True
              Exit For
          End Select
        Next
        If added = False Then
          .AddItem f.Value
          .List(.ListCount - 1, 1) = f.Offset(, -8).Value
          .List(.ListCount - 1, 2) = f.Offset(, -5).Value
          .List(.ListCount - 1, 3) = f.Offset(, -3).Value
        End If
        Set f = R.FindNext(f)
      Loop While Not f Is Nothing And f.Address <> cell
      ComboBox1 = UCase(TextBoxSearch)
      .TopIndex = 0
      Else
      MsgBox "NO ITEM WAS FOUND USING THAT INFORMATION", vbCritical, "DATABASE SHEET ITEM SEARCH"
      ComboBox1.Value = ""
      ComboBox1.SetFocus
    End If
  End With
End Sub
Private Sub UserForm_Initialize()
    With ComboBox1
      .AddItem "AUTEL IM 508"
      .AddItem "HANDY BABY"
      .AddItem "KDX 2"
      .AddItem "NANOCOM"
      .AddItem "SKP 900"
      .AddItem "T300"
      .AddItem "TRS 5000"
      .AddItem "VVDI KEY TOOL"
    End With
End Sub
 
Upvote 0
Could you upload a sample workbook (without sensitive data) to a sharing site like dropbox.com or google drive?
And then share the link here.
 
Upvote 0
Morning,
I have now got it working, i removed Option Explicit for it to work
But maybe you can advise on one thig please.
Below is the code in use.

You will see that when the values are added to the Listbox customers names are Z-A
In this case fisrt is Winston Young then down the page to Paul Ashton

It would be nice if it could be reversed so first would be Paul Ashton then down the page to Winston Young

Have a nice day


Rich (BB code):
Private Sub SearchForm_Click()
  Dim R As Range, f As Range, cell As String, added As Boolean
  Dim sh As Worksheet
  
  Set sh = Sheets("DATABASE")
  sh.Select
  With ListBox1
    .Clear
    .ColumnCount = 5
    .ColumnWidths = "150;210;190;190;50"
    If ComboBox1.Value = "" Then Exit Sub
    Set R = Range("I6", Range("I" & Rows.Count).End(xlUp))
    Set f = R.Find(ComboBox1.Value, LookIn:=xlValues, LookAt:=xlWhole)
    If Not f Is Nothing Then
      cell = f.Address
      Do
        added = False
        For i = 0 To .ListCount - 1
          Select Case StrComp(.List(i), f.Value, vbTextCompare)
            Case 0, 1
              .AddItem f.Value, i
              .List(i, 1) = f.Offset(, -8).Text
              .List(i, 2) = f.Offset(, -5).Value
              .List(i, 3) = f.Offset(, -3).Value
              .List(i, 4) = f.Offset(, -2).Value
              .List(i, 5) = f.Offset(, -1).Value
              
              added = True
              Exit For
          End Select
        Next
        If added = False Then
              .AddItem f.Value
              .List(.ListCount - 1, 1) = f.Offset(, -8).Text
              .List(.ListCount - 1, 2) = f.Offset(, -5).Value
              .List(.ListCount - 1, 3) = f.Offset(, -3).Value
              .List(.ListCount - 1, 4) = f.Offset(, -2).Value
              .List(.ListCount - 1, 5) = f.Offset(, -1).Value
              
        End If
        Set f = R.FindNext(f)
      Loop While Not f Is Nothing And f.Address <> cell
      .TopIndex = 0
    Else
      
    End If
  End With
  
End Sub
 

Attachments

  • EaseUS_2023_07_ 2_11_02_34.jpg
    EaseUS_2023_07_ 2_11_02_34.jpg
    82.7 KB · Views: 17
Upvote 0

Forum statistics

Threads
1,223,234
Messages
6,170,891
Members
452,366
Latest member
TePunaBloke

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