Hi everyone!
I just tried populating a userform using this piece of code:
Rng, Rw, Cell, rFilter are dimmed as Range; c and r as long, MyData() as Variant. That piece of code is something I adapted from an online finding.
This code filters a table according to 3 possible filters. It then fills the listbox with what's left from the filtered table. It works nicely until in another sub I try to get the values.
Whenever my code contains something like
, I get an error 424 "Object required".
Could you kindly explain to me what's happening here? I usually fill my listboxes with .AddItem; however here I have >10 columns and was thus obligated to fill my listbox that way.
Thanks!
I just tried populating a userform using this piece of code:
Code:
Set rFilter = ThisWorkbook.Worksheets("data").ListObjects("Table5").DataBodyRange
With Sheet2
If Not .AutoFilterMode Then .Range("A1").AutoFilter
If Not ligne = "" Then
rFilter.AutoFilter field:=2, Criteria1:=ligne
End If
If Not code = "" Then
rFilter.AutoFilter field:=3, Criteria1:=code
End If
If Not lot = "" Then
rFilter.AutoFilter field:=4, Criteria1:=lot
End If
On Error GoTo attheend 'exit sub if the following line creates an error (occurs when there is no cell left after filtering
Set Rng = rFilter.Cells.SpecialCells(xlCellTypeVisible)
For Each Rw In Rng.Rows
c = c + 1
ReDim Preserve MyData(1 To Rng.Columns.Count, 1 To c)
For Each Cell In Rw.Cells
r = r + 1
MyData(r, c) = Cell.Value
Next Cell
r = 0
Next Rw
Me.LbPreview.List = WorksheetFunction.Transpose(MyData)
End With
Rng, Rw, Cell, rFilter are dimmed as Range; c and r as long, MyData() as Variant. That piece of code is something I adapted from an online finding.
This code filters a table according to 3 possible filters. It then fills the listbox with what's left from the filtered table. It works nicely until in another sub I try to get the values.
Whenever my code contains something like
Code:
Me.LbPreview.List(1, 0).Value
Could you kindly explain to me what's happening here? I usually fill my listboxes with .AddItem; however here I have >10 columns and was thus obligated to fill my listbox that way.
Thanks!