highlight option buttons on userform based on selected button and pop up message

Alaa mg

Active Member
Joined
May 29, 2021
Messages
343
Office Version
  1. 2019
hi experts

I have userfrom contains multipage and frame and there are options buttons and I have command button . so what I want when selected option button (PURCHASE) and press command button then highlight the optionbutton (purchase) by light green and pop up message "the selected option button is purchase", "are you sure ?" if I press yes then continue the procedure like copy data from textbox,combobox to sheet if I press no then should no selected any options and exit sub .with considering change the color is different for rest of options buttons red,blue ... when select any optionbutton
12.PNG
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
Try this:

Change in the code OptionButton1, OptionButton2, OptionButton3, OptionButton4 by the names of your controls.

Rich (BB code):
Private Sub CommandButton1_Click()
  Dim continue As Boolean
  
  Select Case True
    Case OptionButton1: continue = HighlightButton(OptionButton1, vbGreen)
    Case OptionButton2: continue = HighlightButton(OptionButton2, vbRed)
    Case OptionButton3: continue = HighlightButton(OptionButton3, vbBlue)
    Case OptionButton4: continue = HighlightButton(OptionButton4, vbYellow)
  End Select
  If continue = False Then
    Exit Sub
  End If
  '
  ' continue the procedure
  '
End Sub

Function HighlightButton(OpButton As MSForms.OptionButton, thecolor)
  With OpButton
    .BackColor = thecolor
    If MsgBox("The selected option button is " & .Caption & ", are you sure ?", _
      vbYesNo + vbQuestion) = vbYes Then
      HighlightButton = True
    Else
      .BackColor = Me.BackColor
      .Value = False
    End If
  End With
End Function
 
Upvote 0
Solution
I'm glad to help you. Thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,659
Messages
6,120,786
Members
448,994
Latest member
rohitsomani

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