?
Solved

Determine if more than one item selected in listbox

Posted on 2011-09-29
4
Medium Priority
?
262 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 2000 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes how you can use Custom Document Properties to store settings and other information in your workbook so that they will be available the next time you open the workbook.
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
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…
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.

840 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