listbox.selected(x)=true not working correctly

bradyboyy88

Well-known Member
Joined
Feb 25, 2015
Messages
562
So I have created a similar filter feature on a userform that imitates that used in excel when you do the filter feature. My code creates a frame with a listbox that fills the listbox with a bunch of items and when the user selected the ones to filter on and hits submit it loads these selected items into a collection. Well when you rehit the filter button to show the frame I wanted it to reselect the items in the listbox from the collection. The code works as expected and does return true correctly when looping through the listbox contents (using doesitemexist function) but for some reason I cannot highlight the item and returns false in message box since its not highlighted. Here is the code:

Code:
Private Sub HighlightCollectionItems(ByRef coll As Collection)
    
    If coll Is Nothing Then Exit Sub


    Dim X As Integer
    For X = 1 To FilterBoxListbox_BROWSE.ListCount - 1
        If DoesItemExist(coll, FilterBoxListbox_BROWSE.List(X)) Then
            FilterBoxListbox_BROWSE.Selected(X) = True
            MsgBox FilterBoxListbox_BROWSE.Selected(X)
        End If
    Next
End Sub
 
Last edited:

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.

Forum statistics

Threads
1,223,164
Messages
6,170,444
Members
452,326
Latest member
johnshaji

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