Remove focus from option button

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
3,908
Office Version
  1. 2007
Platform
  1. Windows
Hi,
This is the code for my form.

When the userform first opens i see the options of 41601 & 41835 neither of which are at this point selected.
Lets assume i select 41601 i now see the dot in the option button.
Ive noticed ive made a mistake & should of selected 41835

On the form i have a commandbutton2 which should call userform_initialize and then show me 41601 & 41835 like at the start.
This does happen BUT the incorrectly selected option in this case 41601 is shown as selected BUT i need neither to be selected


Rich (BB code):
Private Sub CommandButton1_Click()
    
 With ThisWorkbook.Worksheets("RANGER")
    If OptionButton3.Value = True Then .Cells(lastrow + 5, 9).Value = "N 41601-501-41": OptionButton3.Value = False
    If OptionButton4.Value = True Then .Cells(lastrow + 5, 9).Value = "N 41803-501-42": OptionButton4.Value = False
    If OptionButton5.Value = True Then .Cells(lastrow + 5, 9).Value = "V 41803-501-43": OptionButton5.Value = False
 
 
    With .Range("I5")
        .Font.Size = 14
        .Font.Name = "Calibri"
        .Font.Bold = True
        .HorizontalAlignment = xlCenter
        .VerticalAlignment = xlVAlignCenter
    End With

    With Sheets("RANGER")
        If .AutoFilterMode Then .AutoFilterMode = False
        x = .Cells(.Rows.Count, 5).End(xlUp).Row
        .Range("A4:I" & x).Sort Key1:=Range("B5"), Order1:=xlAscending, Header:=xlGuess
    End With

    Unload RangerPcbNumber
    End With
    MsgBox "DATABASE HAS BEEN UPDATED", vbInformation, "SUCCESSFUL MESSAGE"
End Sub

Private Sub CommandButton2_Click()
Call UserForm_Initialize
End Sub

Private Sub OptionButton1_Change()
        If OptionButton1.Value = True Then
        OptionButton2.Visible = False
        OptionButton3.Visible = True
        End If
        End Sub
Private Sub OptionButton2_Change()
        If OptionButton2.Value = True Then
        OptionButton1.Visible = False
        OptionButton4.Visible = True
        OptionButton5.Visible = True
        End If
        End Sub
Private Sub OptionButton1_Click()
        If OptionButton1.Value = True Then
        OptionButton4.Visible = False
        OptionButton5.Visible = False
        End If
        End Sub
Private Sub OptionButton2_Click()
        If OptionButton2.Value = True Then
        OptionButton3.Visible = False
        End If
        End Sub
Private Sub OptionButton4_Click()
        If OptionButton4.Value = True Then
        OptionButton5.Visible = False
        End If
        End Sub
Private Sub OptionButton5_Click()
        If OptionButton5.Value = True Then
        OptionButton4.Visible = False
        End If
        End Sub
Private Sub UserForm_Initialize()
        OptionButton1.Visible = True
        OptionButton2.Visible = True
        OptionButton3.Visible = False
        OptionButton4.Visible = False
        OptionButton5.Visible = False
        End Sub
 

Some videos you may like

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
3,908
Office Version
  1. 2007
Platform
  1. Windows
This works but its not the correct to do it

Rich (BB code):
Private Sub CommandButton2_Click()
Unload RangerPcbNumber
RangerPcbNumber.Show
End Sub
 

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
3,908
Office Version
  1. 2007
Platform
  1. Windows
Now changed to CheckBox and works for me
 

Watch MrExcel Video

Forum statistics

Threads
1,127,552
Messages
5,625,460
Members
416,107
Latest member
AVaes

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
Top