Filter data in listbox based on three conditions by selected from combobox

tubrak

Board Regular
Joined
May 30, 2021
Messages
216
Office Version
  1. 2019
Platform
  1. Windows
Hi
I have this code is designed by DanteAmore.
it will populate data for column A,B and the column contains date in header with match selected date from combobox1
the column date will contains numeric values.
now I add combobox2 contains three condition (not zero, zero, unknown)
when select date from combobox1 will populate data after matching the date is in header in row1 and when select not zero from combobox2 then will populate data except containing zero in column(3) in listbox . when select date from combobox1 will populate data after matching the date is in header in row1 , when select zero from combobox2 then will populate data except containing not zero in column(3) in listbox . when select date from combobox1 will populate data after matching the date is in header in row1 , when select unknown from combobox2 then will populate data for all of values without any exception .

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 + 1, ";", "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("D1", 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
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN

Forum statistics

Threads
1,215,069
Messages
6,122,952
Members
449,095
Latest member
nmaske

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