?
Solved

Determine if more than one item selected in listbox

Posted on 2011-09-29
4
Medium Priority
?
259 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

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