Home |
Search |
Today's Posts |
#1
|
|||
|
|||
Maximum selections in a mutil list box
Is there a way I can set a maximum number of user selections within a
listbox? I want users to be able to compare my institution with others but limit the 'basket size' to say 8 or 10. Thanks, Martin |
#2
|
|||
|
|||
Maximum selections in a mutil list box
I created a small userform with a listbox, label and two commandbuttons (cancel
& ok) on it. This was the code behind the userform: Option Explicit Private Sub CommandButton1_Click() Unload Me End Sub Private Sub ListBox1_Change() Dim MaxSelections As Long Dim iCtr As Long Dim sCtr As Long MaxSelections = 8 sCtr = 0 Me.Label1.Caption = "" For iCtr = 0 To Me.ListBox1.ListCount - 1 If Me.ListBox1.Selected(iCtr) Then sCtr = sCtr + 1 If sCtr MaxSelections Then Beep Me.Label1.Caption = "Too many Selected" Exit For End If End If Next iCtr Me.CommandButton2.Enabled = ((sCtr <= MaxSelections) And (sCtr 0)) End Sub Private Sub UserForm_Initialize() Dim iCtr As Long With Me.ListBox1 .MultiSelect = fmMultiSelectMulti For iCtr = 1 To 15 .AddItem "asdf" & iCtr Next iCtr End With Me.Label1.Caption = "" 'make them select at least one item Me.CommandButton2.Enabled = False End Sub Martin wrote: Is there a way I can set a maximum number of user selections within a listbox? I want users to be able to compare my institution with others but limit the 'basket size' to say 8 or 10. Thanks, Martin -- Dave Peterson |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Multiple selections from a drop down list in Excel... | Excel Worksheet Functions | |||
maximum value in a list less than specified value | Excel Discussion (Misc queries) | |||
Filtered list & maximum no columns problem | Excel Discussion (Misc queries) | |||
Extracting Values on one list and not another | Excel Discussion (Misc queries) | |||
maximum size of a Microsoft Excel list for a pivot table | Excel Discussion (Misc queries) |