Validate if option button selected at least one selection from a multiselect listbox has also been selected

NorthbyNorthwest

Board Regular
Joined
Oct 27, 2013
Messages
154
Office Version
  1. 365
Hi, everyone. Hope someone can help. I have a dozen sets of yes/no option buttons on a user form. Underneath each set yes/no option buttons is a multiselect list box. How can I validate the user has selected at least one item from the corresponding list box if he or she selected the no option button in response to a question? If the user has missed making one or more list box selections I want to send message as a reminder. Again, the user is only required to make a list box selection if they have selected the no option button to the question above.
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
Hi NorthbyNorthwest,

maybe add a frame to your set of optionbuttons and the listbox. I added a commandbutton for the check with a code like this (change names to fit):
VBA Code:
Private Sub CommandButton2_Click()

  Dim lngLBCounter As Long
  Dim blnSelected As Boolean
 
  If optNo Then
    For lngLBCounter = 0 To ListBox1.ListCount - 1
      If ListBox1.Selected(lngLBCounter) = True Then
        blnSelected = True
      End If
    Next lngLBCounter
    If Not blnSelected Then
      MsgBox "wrong choice"
    Else
      MsgBox "All´s well"
      ListBox1.Enabled = False
    End If
  Else
    MsgBox "All´s well"
    ListBox1.Enabled = False
  End If

End Sub

Private Sub optNo_Click()

  ListBox1.Enabled = True

End Sub

Private Sub UserForm_Initialize()

ListBox1.Enabled = False

End Sub
HTH,
Holger
 
Upvote 0
Solution
Hi NorthbyNorthwest,

maybe add a frame to your set of optionbuttons and the listbox. I added a commandbutton for the check with a code like this (change names to fit):
VBA Code:
Private Sub CommandButton2_Click()

  Dim lngLBCounter As Long
  Dim blnSelected As Boolean
 
  If optNo Then
    For lngLBCounter = 0 To ListBox1.ListCount - 1
      If ListBox1.Selected(lngLBCounter) = True Then
        blnSelected = True
      End If
    Next lngLBCounter
    If Not blnSelected Then
      MsgBox "wrong choice"
    Else
      MsgBox "All´s well"
      ListBox1.Enabled = False
    End If
  Else
    MsgBox "All´s well"
    ListBox1.Enabled = False
  End If

End Sub

Private Sub optNo_Click()

  ListBox1.Enabled = True

End Sub

Private Sub UserForm_Initialize()

ListBox1.Enabled = False

End Sub
HTH,
Holger
Thanks so much for the help, Holger. I'll give it a go.
 
Upvote 0

Forum statistics

Threads
1,214,919
Messages
6,122,260
Members
449,075
Latest member
staticfluids

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top