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

Alaa mg

Active Member
Joined
May 29, 2021
Messages
262
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

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)

DanteAmor

Well-known Member
Joined
Dec 3, 2018
Messages
15,234
Office Version
  1. 2013
Platform
  1. Windows
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
 
Solution

DanteAmor

Well-known Member
Joined
Dec 3, 2018
Messages
15,234
Office Version
  1. 2013
Platform
  1. Windows
I'm glad to help you. Thanks for the feedback.
 

Forum statistics

Threads
1,175,586
Messages
5,898,317
Members
434,703
Latest member
azenk

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