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

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)

Forum statistics

Threads
1,224,823
Messages
6,181,176
Members
453,021
Latest member
Justyna P

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