Listbox issue

The Grim Discovery

Board Regular
Joined
Jan 23, 2015
Messages
246
Office Version
  1. 365
Platform
  1. Windows
Hi Excel peoples

I'm using a Listbox which contains three selectable items - the idea being that people can select any number/combination of the three as they see fit. It works fine but the linked cell reports '0' when more than 1 item on the listbox is selected. I've read around and the only answer seems to be use VBA which I dont understand and makes my brain hurt.

Is there a quick fix for this or an alternative that anybody would recommend? The key features being that any permutation of the three must be selectable and that whatever is picked can be counted easily.

Thanks in advance for your time & willingness to share knowledge.
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
for multi pick lists, you have to scan the entire list to determine what is selected....

Rich (BB code):
For i = 0 To ListBox1.ListCount - 1
If ListBox1.Selected(i) = True  Then msgbox ListBox1.List(i)
Next i
 
Last edited:
Upvote 0
What you are looking for is difficult with Forms ListBoxes.
Three checkboxes might be better.

If you need to use a listbox, you could put this as the control's Assigned Macro
Code:
Sub ListBox1_Change()
    Dim CheckedSum As Long, i As Long
    With ActiveSheet.Shapes("List Box 1").OLEFormat.Object
        For i = 1 To .ListCount
        CheckedSum = CheckedSum - ((2 ^ (i - 1)) * .Selected(i))
        Next i
    End With
    Range("B1").Value = CheckedSum
End Sub
It will put a number in B1 that represents which items on the list are checked
0- no checked
1- item 1 checked
2 - item 2 checked
3- items 1 and 3 checked
4 - item 3 checked
5 - items 1 and 3 checked
6 - items 2 and 3 checked
7 - items 1, 2 and 3 checked

etc.

(think of numbers in binary 010 means item 2 checked)
 
Upvote 0

Forum statistics

Threads
1,224,818
Messages
6,181,152
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