Hi thanks for the example, but what i need is not completely in the example. If you can help Iam having two problems, first I would like my combobox3 filter my listbox2 and also the combobox3 should filter the listbox2 if the information in the "data" sheet on column D equals -1 for that lane. This is how the information in my data sheet looks like:
A B C D
INVOICE CONTAINER LANE STATUS
B 1 2 -1
this is the code iam using:
Sub populateComboBox1(sCombo1 As String)
Dim rngCell As Range
Dim rSource As Range
Dim CW As String
Dim WS As Worksheet
Dim lMaxRows As Long
Dim lRow As Long
Dim i As Integer
Set WS = Sheets("Combo2")
WS.AutoFilterMode = False
WS.Cells.Clear
Sheet11.AutoFilterMode = False
Sheet11.Range("A:B").Copy
WS.Range("A1").PasteSpecial
Set rngCell = WS.Range("A:B").Find("*", Cells(1, 1), , , xlByRows, xlPrevious)
If rngCell Is Nothing Then GoTo End_Sub
lMaxRows = rngCell.Row
Set WS = Sheets("Combo2")
With WS
For lRow = 1 To lMaxRows
.Cells(lRow, "C") = lRow
Next lRow
.Range("a:a").AutoFilter field:=1, Criteria1:="<>" & sCombo1
lMaxRows = .Cells(Rows.Count, "C").End(xlUp).Row
End With
If (lMaxRows > 1) Then
WS.Rows("2:" & lMaxRows).Delete
End If
WS.AutoFilterMode = False
Set rSource = WS.Cells(2, 3).CurrentRegion
With Me.ListBox2
.ColumnCount = 2
.RowSource = rSource.Address(External:=True)
For i = 1 To rSource.Columns.Count
CW = CW & rSource.Columns(i).Width & ";"
Next i
.ColumnWidths = CW
.ListIndex = -1
.Width = 180
.MultiSelect = fmMultiSelectMulti
End With
End_Sub:
Set rngCell = Nothing
End Sub
Bookmarks