With userforms is it possible to deselect the optionbox after clicking it again when it states set to true?

Bassie

Board Regular
Joined
Jan 13, 2022
Messages
66
Office Version
  1. 2019
Platform
  1. Windows
Hi,

I want to be able to deselect the entire optionbox by clicking the option again (like a checkbox) is this possible without doing it via another button?

Pic:
1683892353197.png

So when I click "In Entire String" again I want to deselect them both.

Regards,
Bassie
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
Hi there

Does it have to be an Optionbutton? By Using a Checkbox you can select and deselect a Checkbox.
 
Upvote 0
If it cannot be a Checkbox then try the below...

If I look correctly it looks like you have these inside a Frame on the Userform... Try...

VBA Code:
Option Explicit
Private Sub Frame1_Click() 'Replace Frame1 with the name of your Frame Control
Dim Ctrl As Control
  For Each Ctrl In Me.Controls
    If TypeOf Ctrl Is MSForms.OptionButton Then
            If Ctrl.Value Then
                Ctrl.Value = False
                Exit For
            End If
        End If
  Next Ctrl
End Sub

Then just click anywhere inside the frame...
 
Upvote 1
Solution
If it cannot be a Checkbox then try the below...

If I look correctly it looks like you have these inside a Frame on the Userform... Try...

VBA Code:
Option Explicit
Private Sub Frame1_Click() 'Replace Frame1 with the name of your Frame Control
Dim Ctrl As Control
  For Each Ctrl In Me.Controls
    If TypeOf Ctrl Is MSForms.OptionButton Then
            If Ctrl.Value Then
                Ctrl.Value = False
                Exit For
            End If
        End If
  Next Ctrl
End Sub

Then just click anywhere inside the frame...
Hi This does work thanks!

Is it also possible to have it so if the user clicks the same option again that it turns them all off?

Or am I being dumb and is it also possible for check boxes to be dependent on eachother so that you can only choose one?

- Bassie
 
Upvote 0
I finally found something:

VBA Code:
Private PreviousOption As Boolean
Private Sub RemoveBlanksUp_Click()

If PreviousOption = True Then RemoveBlanksUp = False

PreviousOption = False

End Sub

Private Sub RemoveBlanksUp_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
Dim Ctrl As control
  
If RemoveBlanksUp = True Then RemoveBlanksUp = False: PreviousOption = True

End Sub
 
Upvote 0
Hi This does work thanks!
The marked solution has been changed accordingly. In your future questions, please mark the post as the solution that actually answered your question, instead of your feedback message as it will help future readers. No further action is required for this thread.
 
Upvote 0

Forum statistics

Threads
1,215,338
Messages
6,124,358
Members
449,155
Latest member
ravioli44

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