Results 1 to 9 of 9

VBA Userform Issue - Command Button / msg Box

Threaded View

teeks VBA Userform Issue - Command... 01-07-2010, 08:19 AM
Andy Pope Re: VBA Userform Issue -... 01-07-2010, 09:42 AM
Andy Pope Re: VBA Userform Issue -... 01-07-2010, 09:43 AM
teeks Re: VBA Userform Issue -... 01-07-2010, 10:29 AM
Andy Pope Re: VBA Userform Issue -... 01-07-2010, 10:35 AM
  1. #1
    Registered User
    Join Date
    01-07-2010
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    13

    VBA Userform Issue - Command Button / msg Box

    I have a command button that when I click drops the contents of numerous list boxes into excel. I wanted to add a message box to tell the user when they have not selected an item in one of the list boxes. They need to select at least one item in each list box. Example below. It is not working, even if I select an item in each list box I still get the "Please select one question!" message box displayed rather than a successful submission. I tried and if then else statement but it did the same. need it to submit the data if items selected in all list boxes, message box if not all items selected. Any help much appreciated. Code i'm trying is;

    Private Sub CommandButton1_Click()
    
    Dim lItem As Long
    
        For lItem = 0 To ListBox1.ListCount - 1
    
            If ListBox1.Selected(lItem) = True Then
    
                Sheet4.Range("A65536").End(xlUp)(2, 1) = ListBox1.List(lItem)
        
     End If
     
    Next
    
    Dim zItem As Long
    
        For zItem = 0 To ListBox1.ListCount - 1
    
    If ListBox1.Selected(zItem) = False Then
                    
    MsgBox "Please select one question!" _
    , vbExclamation + vbOKOnly, "Criteria not selected"
    
    Exit Sub
    
    End If
    
    End Sub
    Last edited by teeks; 01-07-2010 at 09:51 AM. Reason: did not add code tags. hope I have done this correctly now. Apologies

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1