Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Martin
 
Posts: n/a
Default 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   Report Post  
Dave Peterson
 
Posts: n/a
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Multiple selections from a drop down list in Excel... JMW Excel Worksheet Functions 3 November 9th 05 05:05 PM
maximum value in a list less than specified value DBYRON Excel Discussion (Misc queries) 1 October 5th 05 08:40 PM
Filtered list & maximum no columns problem claytorm Excel Discussion (Misc queries) 0 August 24th 05 10:52 AM
Extracting Values on one list and not another B Schwarz Excel Discussion (Misc queries) 4 January 7th 05 01:48 PM
maximum size of a Microsoft Excel list for a pivot table Bob Carey Excel Discussion (Misc queries) 1 January 6th 05 04:50 PM


All times are GMT +1. The time now is 02:32 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"