force optionbutton selection

mdorey

Board Regular
Joined
Oct 6, 2011
Messages
64
hello all...

I have the following macro to name the sheet and it's working fine

Code:
Private Sub CommandButton2_Click()   
Dim X As Variant


    If OptionButton1.Value = True Then
    X = "1"
    ElseIf OptionButton2.Value = True Then
    X = "2"
    ElseIf OptionButton3.Value = True Then
    X = "3"
    ElseIf OptionButton4.Value = True Then
    X = "4"
    ElseIf OptionButton5.Value = True Then
    X = "5"
    ElseIf OptionButton6.Value = True Then
    X = "6"
    End If
    
    If TextBox1 = "" Then
    MsgBox "Insert Name"
    Exit Sub
    End If
    
    
   Sheets(Sheets.Count).Name = TextBox1 & " " & X & " " & Date
   Unload Me
      
End Sub

I just need some help to force the users to select any of the optionbuttons

Any sugest pls??
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
hello all...

I have the following macro to name the sheet and it's working fine

Code:
Private Sub CommandButton2_Click()   
Dim X As Variant


    If OptionButton1.Value = True Then
    X = "1"
    ElseIf OptionButton2.Value = True Then
    X = "2"
    ElseIf OptionButton3.Value = True Then
    X = "3"
    ElseIf OptionButton4.Value = True Then
    X = "4"
    ElseIf OptionButton5.Value = True Then
    X = "5"
    ElseIf OptionButton6.Value = True Then
    X = "6"
[B][COLOR="#FF0000"]    Else
      MsgBox "You must select an OptionButton!"
      Exit Sub[/COLOR][/B]
    End If
    
    If TextBox1 = "" Then
    MsgBox "Insert Name"
    Exit Sub
    End If
    
    
   Sheets(Sheets.Count).Name = TextBox1 & " " & X & " " & Date
   Unload Me
      
End Sub

I just need some help to force the users to select any of the optionbuttons
I think what I added in red above will do that.
 
Upvote 0
Assuming your Option Captions are 1,2,3 etc. you could use this script:
Code:
Dim i As Integer
For i = 1 To 6
If Me.Controls("OptionButton" & i) = True Then
x = Me.Controls("OptionButton" & i).Caption
End If
Next
 
Upvote 0

Forum statistics

Threads
1,213,513
Messages
6,114,072
Members
448,546
Latest member
KH Consulting

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