ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Radio Button Group value using VBA (https://www.excelbanter.com/excel-programming/297972-radio-button-group-value-using-vba.html)

Rashdeep

Radio Button Group value using VBA
 
Hello,
I have a small issue in trying to find out if one of the radio buttons
in the group of radio buttons is clicked. i.e.:
Group: radioGrp1
Radio Button 1: radioBtn1
Radio Button 2: radioBtn2
Radio Button 3: radioBtn3
Command Button: cmdBtn

What value should be expected from the group if a user selects one of
the radio buttons after the user clicks on the Command Button. The
radio buttons are all "unclicked" upon form load and the Command Button
just validates that the user has selected on of the radio buttons.

Thank you for your help.


---
Message posted from http://www.ExcelForum.com/


Melanie Breden

Radio Button Group value using VBA
 
Hello,
I have a small issue in trying to find out if one of the radio buttons
in the group of radio buttons is clicked. i.e.:
Group: radioGrp1
Radio Button 1: radioBtn1
Radio Button 2: radioBtn2
Radio Button 3: radioBtn3
Command Button: cmdBtn

What value should be expected from the group if a user selects one of
the radio buttons after the user clicks on the Command Button. The
radio buttons are all "unclicked" upon form load and the Command Button
just validates that the user has selected on of the radio buttons.


write the following procedure into the code module from the UserForm:

Private Sub cmdBtn_Click()
MsgBox CheckOptionButton(Me, "radioGrp1")
End Sub

And this function in a standard module:

Function CheckOptionButton(objForm As Object, strGroupName As String) _
As String
Dim ctrl As Control

For Each ctrl In objForm.Controls
If TypeName(ctrl) = "OptionButton" Then
If ctrl.GroupName = strGroupName And ctrl.Value Then
CheckOptionButton = ctrl.Caption
' reset OptionButton
ctrl.Value = False
End If
End If
Next ctrl
End Function

--
Regards
Melanie Breden
- Microsoft MVP für Excel -

http://excel.codebooks.de (Das Excel-VBA Codebook)



All times are GMT +1. The time now is 08:57 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com