Insert checkbox inside the combobox list for multiple selection

How to insert CheckBoxes to the list present in ComboBox?
Saha cAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

GrahamSkanRetiredCommented:
What is your environment, VB Classic (VB6), .Net or VBA?. You have indicated all three in your list of topics.

In VBA you can use a ListBox with ListStyle = fmListStyleOption.
0
Roy CoxGroup Finance ManagerCommented:
VBA UserForm ComboBox does not have this Property ListBoxes do. You can set this when the UserForm Initialises or manually in it's Properties Window.
Private Sub UserForm_Initialize()
Me.ListBox1.ListStyle = fmListStyleOption

End Sub

Open in new window


 I'm sure the same applies to VB.Net


ListBox Class
0
Saha cAuthor Commented:
OK thank you...
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Saha cAuthor Commented:
How can i filter data based on multi selection values in Listbox using VBA?
0
Roy CoxGroup Finance ManagerCommented:
We still do not know what coding language you are using. Also, this is a further question and should be asked on its own. This question needs closing by awarding the poinst after amending the Tags
0
Saha cAuthor Commented:
I am using VBA language only.
i got to know that checkbox options are only available with ListBoxes.
I am asking  when we select multiple options in that listbox , can we use those values to filter at a time.
0
Roy CoxGroup Finance ManagerCommented:
You are  really still limited by two filter criteria for AutoFilter even using VBA this applies. You can build an array.

This is sample code to detect what has been selected in the ListBox, but as I said before, this should be a new question.

 Dim Msg As String
      Dim iX As Integer
      Msg = "You selected" & vbNewLine
      For iX = 0 To Me.ListBox1.ListCount - 1
          If ListBox1.Selected(iX) Then
              Msg = Msg & Me.ListBox1.List(iX) & vbNewLine
          End If
      Next i
      MsgBox Msg

Open in new window

0
Roy CoxGroup Finance ManagerCommented:
This code assumes you have a ListBox1 and the data is on Sheet1 starting in A1

Sub FilterFromListBox()
    Dim iX As Integer
    Dim Var As Variant
    
    ReDim Var(0)
    Application.ScreenUpdating = False
    For iX = 0 To ListBox1.ListCount - 1
        If Me.ListBox1.Selected(iX) Then
            Var(UBound(Var)) = Me.ListBox1.List(iX)
            ReDim Preserve Var(UBound(Var) + 1)
        End If
    Next iX
    
    Sheet1.Range("A1").CurrentRegion.AutoFilter Field:=3, Criteria1:=Var, Operator:=xlFilterValues
    Application.ScreenUpdating = True
    
End Sub

Open in new window

0
Roy CoxGroup Finance ManagerCommented:
Thanks Martin. It seems to be Excel VBA required
0
Saha cAuthor Commented:
i have one sheet in that, first we have to select year and next we have to select multiple  work week values from list box. for those selected values it has to filter the given table.
For year it is working fine but for multiple work week values it is not filtering properly.
Please find the attached dummy sheet.
Book.xlsm
0
Martin LissOlder than dirtCommented:
Thank you for attaching a workbook, but it doesn't work at all. We need one that has the controls filled with data. Also when I went to open your form I got this message which is worrisome.2018-04-25_06-39-10.png
0
Roy CoxGroup Finance ManagerCommented:
Do you intend using the UserForm or the sheet controls. A UserForm is more reliable than ActiveX controls on a sheet.

I've fixed some of your example. there is no button on the sheet, but let me know if this is along the correct lines.

Also, here's my example of filtering from a UserForm
FilterForm.xlsm
Book.xlsm
0
Saha cAuthor Commented:
Thank you for examples. I want with ActiveX controls only. But it is not filtering multiple selection of  workweeks.
0
Roy CoxGroup Finance ManagerCommented:
I haven't included code for that in the example yet because it's not clear what you are doing.
0
Saha cAuthor Commented:
Please find the attached sheet....
Book.xlsm
0
Saha cAuthor Commented:
just i want to do  multiple selection and that should reflect in that table.
But it is not filtering for single selection also...
0
Roy CoxGroup Finance ManagerCommented:
Your new example totally ignores what I did in the previous example.
0
Saha cAuthor Commented:
No no its same only just i have two more buttons for refresh and autofilter.
0
Saha cAuthor Commented:
sorry for typo mistake.
Only i have added two buttons . I need only multiple selection should be reflect in available table.
0
Roy CoxGroup Finance ManagerCommented:
I've completely re-built your workbook. It occassionally crashed with a dll error.

Try this

The combobox filters by year

Make selections in the Listbox, then press the Filter by WW button to filter by selected items

The Reset Filter button clears any filters on the data.
EE_FilterExample.xlsm
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Saha cAuthor Commented:
OK thank you..
i have one doubt please can u explain me that. Why You kept this listbox procedure empty? Then how values are displaying in listbox?

Private Sub ListBox1_Click()

End Sub

Private Sub Worksheet_Activate()
''/// populate the ListBox and ComboBox
''///only use cells containing value, dynamic so data can be entered and reflect in list
    With Sheet3
        Me.ComboBox1.List = .Range(.Cells(2, 1), .Cells(.Rows.Count, 1).End(xlUp)).Value
        Me.ListBox1.List = .Range(.Cells(2, 2), .Cells(.Rows.Count, 2).End(xlUp)).Value
    End With
End Sub
0
Saha cAuthor Commented:
Sir, can you explain me this part of code...
0
Roy CoxGroup Finance ManagerCommented:
You don't load the ListBox or ComboBox with the Change or Click event, if you do it means that every time you use it it will re-load.

My code loads it when the worksheet is activated, so it is refreshed with any changes to the List.
0
Roy CoxGroup Finance ManagerCommented:
The code works as required
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.