Solved

Determine if more than one item selected in listbox

Posted on 2011-09-29
4
249 Views
Last Modified: 2012-08-13
vba 2003 excel
userform listbox
frmliststyleoption.
multiselectext

I simply trying to determine if I have more than 1 item selected in listbox ?
when pressing a command button


Thanks
fordraiders
Dim Msg As String, h As Integer
    Msg = ""
    With Me.ListBox1
        For h = 0 To .ListCount - 1
            If h > 1 Then
              MsgBox "Multiple Items Selected", vbCritical, "Item Selection"
               Exit Sub
            End If
        Next h
    End With

Open in new window

0
Comment
Question by:fordraiders
  • 2
4 Comments
 
LVL 5

Expert Comment

by:Khalid Mehmood Awan
ID: 36817383
http://www.ozgrid.com/forum/showthread.php?t=17473&page=1

VB-6    http://www.vb6.us/tutorials/indepth-vb6-listbox-tutorial
VB.NET (below)

Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If ListBox1.SelectedItems.Count > 1 Then

            MessageBox.Show("Multiple selcted")
        Else
            MessageBox.Show("No item or Single item selected")

        End If
    End Sub
End Class

Open in new window

0
 
LVL 3

Author Comment

by:fordraiders
ID: 36817451
vba does not have property "SelectedItems"
0
 
LVL 85

Accepted Solution

by:
Rory Archibald earned 500 total points
ID: 36890785
You have to loop:
Dim n As Long, Counter as Long

With Me.Listbox1

For n = 0 To .ListCount - 1

   If .Selected(n) Then Counter = Counter + 1
Next n
msgbox Counter
End With

Open in new window

0
 
LVL 3

Author Closing Comment

by:fordraiders
ID: 36907715
Thanks
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

A2 = A1 That kind of cell reference is relative.  If you copy it from A2 to B2, then B2 will get this: B2 = B1 That's all fine and good, but if you then insert a new row above row 2, you'll find: A3 = A1 B3 = B1 This is intentional. …
Introduction This Article is a follow-up to my Mappit! Addin Article (http://www.experts-exchange.com/A_2613.html), it was inspired by an email posting I made to EUSPRIG (http://www.eusprig.org/index.htm), I will briefly cover: 1) An overvie…
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now