I have a worksheet table with contacts ("Leads"). I also have a userform to interact with the list ("FormInputs"). On the userform is a Listbox ("ContactList").
When I filter the list for say, "medical" contacts or "client" contacts, the listbox is re-populated with only the filtered results/visible contact names & respective row numbers.
I'm a fairly proficient leach of other people's code
but I have copied, pasted, cut and added so much I no longer know what I'm doing. On top of that, arrays are something I can never seem to get my head around. Is there something simple someone can point out that I'm doing wrong? And please don't say the thing I'm doing wrong is "messing with code". My feelings will be hurt and I'll never be able to lie to others about how great I am . . .
Thank you all!
Sub SetContactList()
Dim ws As Worksheet: Set ws = ThisWorkbook.Sheets("Leads")
Dim tbl As ListObject: Set tbl = ws.ListObjects("LeadTable")
Dim MyArray
Dim rstart As Long: rstart = tbl.AutoFilter.Range.Offset(1).SpecialCells(xlCellTypeVisible).Row
Dim rend As Long: rend = tbl.ListColumns("Contact").Range.Rows.Count + tbl.HeaderRowRange.Row
Dim cstart As Long: cstart = tbl.ListColumns("Row").Range.column
Dim cend As Long: cend = tbl.ListColumns("Contact").Range.column
Dim rng As Range: Set rng = Range(Cells(rstart, cstart), Cells(rend, cend))
With FormInputs.ContactList
.Clear
.ColumnHeads = False
.ColumnCount = 2
MyArray = rng.SpecialCells(xlCellTypeVisible)
.List = MyArray
.ColumnWidths = "0;100"
End With
End Sub
Bookmarks