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
Bookmarks