Hello,
I have a list box with 28 collumns and I would like to use the listbox add item function and don't add certain items based on a value I have found this code but don't know how to add the values from other collumns
You can't use AddItem if you want 28 columns. You have to populate an array with the data and then assign that to the listbox. Which columns are you trying to add?
Dim m As Long Dim myrange As Range Dim wsh As Worksheet Set wsh = Worksheets("Suivi2") m = wsh.Range("A" & wsh.Rows.Count).End(xlUp).Row Me.ListBox1.RowSource = "" With wsh.Sort .SortFields.Clear .SortFields.Add Key:=Range("AB2:AB" & m), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal .SortFields.Add Key:=Range("I2:I" & m), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal ' .SetRange Range("A2:AB" & m) .Header = xlYes .MatchCase = False .Orientation = xlTopToBottom .SortMethod = xlPinYin .Apply End With With wsh ' .AutoFilter .Range("A2:AB" & m).AutoFilter Field:=9, Criteria1:="<>NA", _ Operator:=xlAnd .Range("A2:AB" & m).AutoFilter Field:=28, Criteria1:="=10", _ Operator:=xlAnd End With Set myrange = wsh.Range("A2:AB" & Cells(Rows.Count, "A").End(xlUp).Row).SpecialCells(xlCellTypeVisible) Me.ListBox1.RowSource = myrange.Address
It works almost exactly as i wanted! Perfect! thank you very much, now if i want to extend it to 29 or 30 collumns when i change some value it gives me an error perhaps i'm doing something wrong :-(
With his code it’s working correctly, but when it doesn’t finds the value it shows me the header on the listbox
And to clear the filter I found a way but not working as excepted, I will post the workbook later so it’s better to view...
Bookmarks