简体   繁体   中英

Excel Filter in sheet and populate filtered range in Userform listbox

I'm new to StackOverflow AND Excel/VBA. First i did some Google research to help me with my problem but there was not a good explanation available, i hope you guys can help.

My problem:

I have a worksheet range from A3:V100 that populates my listbox. Now, i use recorded macros with autofilters in my worksheet and i'm adding those macros to buttons in my userform but because the results can be row 5, row 35, row 40, my range isn't correct anymore. How can i set a listbox range only for the filtered rows and not for the whole data rows.

My current range code:

    Sub populateListbox1()

With ListBox1

    .ColumnHeads = True
    .ColumnCount = 30
    .ColumnWidths = "30;30;50;50;60;50;50;50;50;50;50;50;50;0;0;0;0;0;0;0;50;50;0;0;0;0;0;0;0;0"
    .RowSource = Sheet1.Range("A6", Range("AD" & Rows.Count).End(xlUp)).Address
End With

End Sub

I'm asking:

Can anyone give me a correct code for my rowSource range when i applied the autofilters. Or does someone have other ideas to filter my listbox?

Thanks in advance!

If found a way to do this.

I use "Go to special" "Visible cells only" i select my results, copy those value in another sheet. I recorded those steps as a macro.

And after all that i populate my listbox like any other listbox.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM