List Box form control, max 5 selections

MikkelDuif

New Member
Joined
Nov 26, 2016
Messages
9
Hello,

I have a question regarding the List Box in Excel.
I am about to build a dashboard, and what I want to have is a list box where the user can make multiple selection, but no more than 5.

So far, I haven't managed to do it with the list box form control. Is it even possible?
I imagine it can be done as an ActiveX with some coding, but I would rather avoid that.

Thanks a lot!

/Mikkel
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes


Thanks you very much.
I have modified the code a bit, so it returns a number to the left of my list, so I can do a vlookup on another sheet to get them in order.

PHP:
Private Sub ListBox1_Change()
Dim iInd%
Dim i As Integer, Cnt As Integer
Cnt = 0
iInd = ListBox1.ListIndex
For i = 0 To ListBox1.ListCount - 1
If ListBox1.Selected(i) = True Then
Cnt = Cnt + 1
For x = 1 To 5
Sheets("SheetName").Range("ColumnLetter" & i + 1).Value = Cnt
Next x
Else
Sheets("SheetName").Range("ColumnLetter" & i + 1).ClearContents
End If
Next i
If Cnt > 5 Then
ListBox1.Selected(iInd) = False
Sheets("SheetName").Range("ColumnLetter" & i).Clear
MsgBox "Only X can be selected"
End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,270
Messages
6,171,103
Members
452,379
Latest member
IainTru

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