Populate Listbox with non-consecutive columns

gemcgraw

Board Regular
Joined
Mar 11, 2011
Messages
72
I'm writing a routine for a small auto-body repair business. They have a massive workbook loaded with data from online catalogs. Each sheet is broken down by Vendor, Inventory, etc. They would like to select a particular vendor in ComboBox1 (Sheet = Vendor) and then the ListBox populates with Part Descriptions (Sheet= Inventory, column B) and the Price (Sheet = Inventory, Column C).

User selects a vendor in ComboBox1 (populated from the Vendor sheet). I need to do a search on the Inventory sheet in column C. If any cell in C2:C (last row) matches the value of ComboBox1, then the Listbox1 should be populated with the values in columns B & D of the Inventory Sheet... repeating until the last row is reached on the Inventory sheet.

UserFormVendor.ComboBox1

UserFormInventory.ListBox1
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
Do you have 2 userform?
Or is it only one?
If it's one, try this

Code:
Private Sub ComboBox1_Change()
    Dim c As Range
    ListBox1.Clear
    For Each c In Sheets("Inventory").Range("C2", Sheets("Inventory").Range("C" & Rows.Count).End(xlUp))
        If c.Value = ComboBox1.Value Then
            ListBox1.AddItem c.Offset(, -1).Value
            ListBox1.List(ListBox1.ListCount - 1, 1) = c.Offset(, 1).Value
        End If
    Next
End Sub
 
Upvote 0
Hey thanks Dante! Beautiful. I was getting close but was making a mess out of my code. I appreciate the advice!
 
Last edited:
Upvote 0
I'm glad to help you. Thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,590
Messages
6,120,423
Members
448,961
Latest member
nzskater

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