Populate three columns in list box from many columns based on selected date in combobox

tubrak

Board Regular
Joined
May 30, 2021
Messages
218
Office Version
  1. 2019
Platform
  1. Windows
Hi
I have data in SS sheet the headers in row1 in column A is ITEM(1,2,3...) column B is ID the column C,D,E...... contains dates DD/MM/YYYY
and I have userform contains listbox1 , combobox1 . the combobox1 should populate dates from column C : last column (every time add new column will contain date in header)
every column contain date will contain QTY so what I want when select date from combobox1 should populate three columns ITEM, ID , DATE based on selected date from combobox1
I have about 5000 rows in SS sheet
thanks
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
Put the following code in your form. Even if you already have a code to load your combobox, replace it with the following.

The approch of the code is to load all the sheet data in the listbox when activating the userform.
Later when you select a date, it will only show you columns 1, 2 and the column of the selected date. This will make displaying the data very fast.

VBA Code:
Private Sub ComboBox1_Change()
  Dim j As Long
  Dim wds As String
 
  With ComboBox1
    If .ListIndex = -1 Then Exit Sub
    For j = 2 To ListBox1.ColumnCount - 1
      wds = wds & IIf(j = .ListIndex + 2, ";", "0;")
    Next
    ListBox1.ColumnWidths = ";;" & wds
  End With
End Sub

Private Sub UserForm_Activate()
  Dim lr As Long, lc As Long, j As Long
  Dim wds As String
 
  lc = Cells(1, Columns.Count).End(1).Column
  lr = Range("A" & Rows.Count).End(3).Row
  ComboBox1.List = Application.Transpose(Range("C1", Cells(1, lc)).Value)
  With ListBox1
    .ColumnCount = lc
    .List = Range("A2", Cells(lr, lc)).Value
    For j = 0 To ListBox1.ColumnCount - 1
      wds = wds & "0;"
    Next
    .ColumnWidths = wds
  End With
End Sub

----- --
Let me know the result and I'll get back to you as soon as I can.
Sincerely
Dante Amor
----- --
 
Upvote 0
Solution
Hi,
your code does exactly what I described in OP .
much appreciated for your help .:)
 
Upvote 0

Forum statistics

Threads
1,223,214
Messages
6,170,772
Members
452,353
Latest member
strainu

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