VBA - Use a combobox to generate list box items

JohnSmith9945

New Member
Joined
Sep 30, 2022
Messages
3
Office Version
  1. 365
Platform
  1. Windows
Hey! im really struggling to understand how, based on a combobox selection i can pull records into a listbox. Ive tried the below code based on some videos but it still doesnt quite make sense/isnt doing what i need it too.

i just want to to be able to select an ID in the combo box, press apply filter and have that search my table and display all records that have that ID in their row, in the list box.

Any help would be much appreciated!

VBA Code:
Option explicit 
Dim my data As range 

Private sub applyfilternav_click ()
Set mydata  = Worksheets ("dataID").range ("A1").CurrentRegion 
Me.Combobox1.list =mydata.Offset(1).Value 
Me.Listbox1.ColumnCount = 13 
Me.Listbox1.Columnheads = true 
Me.Listbox1.ColumnCount = "10,10,10,10,10,10,10,10,10,10,10,10,10"

Dim mysearchrng as range 
Dim myfindrange as range 
Dim myvaltofind as variant 

With Worksheets("DataIssues") 
myvaltofind =combobox1.value 
set mysearchrng =.Columns("C)
end with 

set myfindrng  = mysearchrng.find(what:=myvaltofind, _ 
Lookat:=xlwhole, _ 
Searchorder: = xlByrows, _ 
Searchdirection: =xlnext, _ 
matchcase: =false)

Listbox1.additem 
with listbox1
.list (.listcount -1, 2)= myfindrng.value
.list (.listcount -1, 0)= myfindrng.offset (0,1).value
.list (.listcount -1, 1)= myfindrng.offset (0,2).value
.list (.listcount -1, 3)= myfindrng.offset (0,4).value

private sub userform_intialize() 
combobox1.list = worksheets("detailsID").range("b2:100").value
end sub
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Code:
for i = 0 to cboBox.listcount - 1      'in vb, counts begin with zero
     lstBox.AddItem  = cboBox.itemdata(i)
next
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,184
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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