Link to home
Start Free TrialLog in
Avatar of Fordraiders
FordraidersFlag for United States of America

asked on

Determine if more than one item selected in listbox

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

Avatar of Khalid Mehmood Awan
Khalid Mehmood Awan
Flag of Pakistan image

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

Avatar of Fordraiders

ASKER

vba does not have property "SelectedItems"
ASKER CERTIFIED SOLUTION
Avatar of Rory Archibald
Rory Archibald
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks