listbox / multi selection filter

ahmad123

New Member
Joined
May 24, 2011
Messages
11
Hi folks,

I have a userform containing a listbox. In this listbox, theres data imported from a column ("Ext Co Visibility Ds") in a big spreadsheet.
What i need to do is to give the user the capability to filter the big spreadsheet by selecting multiple lines in the listbox.

The listbox has to act like a filter for the column "Ext Co Visibility Ds". By filtering that column the user will see the rows corresponding to his selection in the big spreadsheet.

below is my code :

HTML:
Dim rngVendors As Range
Private Sub lbx_Vendors_Click()
 
 
 
    If Me.lbx_Vendors.ListIndex = -1 Then Exit Sub
    Application.ScreenUpdating = False
    On Error Resume Next
    rngVendors.AutoFilter Field:=rngVendors.Column, Criteria1:=Me.lbx_Vendors.Text
 
    Application.ScreenUpdating = True
 
End Sub
Private Sub UserForm_Initialize()
 
    Const VendorCol As String = "I"
    Const HeaderRow As String = "1"
    Sheets("sheet1").Select
    Dim rngUniques As Range
    Set rngUniques = Cells(HeaderRow, Columns.Count).End(xlToLeft).Offset(0, 6)
    Set rngVendors = Sheets("sheet1").Range(VendorCol & HeaderRow, Cells(Rows.Count, VendorCol).End(xlUp))
 
    Application.ScreenUpdating = False
    rngVendors.AdvancedFilter Action:=xlFilterCopy, _
                              CopyToRange:=rngUniques, _
                              Unique:=True
    Set rngUniques = Range(rngUniques.Offset(1, 0), Cells(Rows.Count, rngUniques.Column).End(xlUp))
    ActiveSheet.Sort.SortFields.Clear
    ActiveSheet.Sort.SortFields.Add Key:=rngUniques, _
        SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
    With ActiveWorkbook.Worksheets("sheet1").Sort
        .SetRange rngUniques
        .Header = xlNo
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With
    If rngUniques.EntireColumn.Hidden = False Then rngUniques.EntireColumn.Hidden = True
    Application.ScreenUpdating = True
 
    Me.lbx_Vendors.RowSource = rngUniques.Address
 
End Sub

And can u please modify the code so i will be able to make multi selections in the listbox ???




Thanks to the Gurus <TABLE id=post2543652 class=tborder border=0 cellSpacing=0 cellPadding=6 width="100%" align=center><TBODY><TR><TD class=thead>

</TD></TR><TR><TD style="PADDING-BOTTOM: 0px; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; PADDING-TOP: 0px" class=alt2><!-- user info --><TABLE border=0 cellSpacing=6 cellPadding=0 width="100%"><TBODY><TR><TD noWrap> <!-- BEGIN TEMPLATE: postbit_onlinestatus -->

</TD><TD width="100%"></TD><TD vAlign=top noWrap>



</TD></TR></TBODY></TABLE><!-- / user info --></TD></TR><TR><TD id=td_post_2543652 class=alt1><!-- message, attachments, sig --><!-- icon and title -->
<HR style="BACKGROUND-COLOR: #ebebeb; COLOR: #ebebeb" SIZE=1><!-- / icon and title --><!-- message --><!-- BEGIN TEMPLATE: ad_showthread_firstpost_start --><!-- END TEMPLATE: ad_showthread_firstpost_start --><!-- / message --><!-- attachments -->

</TD></TR></TBODY></TABLE>
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
set the multiselect property of the listbox to "fmMultiselectMulti"
 
Upvote 0

Forum statistics

Threads
1,224,505
Messages
6,179,152
Members
452,891
Latest member
JUSTOUTOFMYREACH

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top