Get Radio Button data

kitsu_ne

New member
Joined
Jan 15, 2014
Messages
16
Reaction score
0
Points
0
Location
http://www.khanacademy.org/profile/killervulpix/#p
Hello,

I have three radio buttons, they are called "NoDateButton", "WeeklyButton", and "MonthlyButton". I'm considering grouping them together, although I'm not sure if that's possible (If you right click them while holding CTRL it will select all of them, then you click on drawing tools and click "Group", but I'm not sure if this is an actul group as far as VBA is concerned). Right now it's grouped as "DateFilterGroup"

I have a macro that I run, but I don't know how to refer to these buttons to determine how to execute my code. Can anyone please help?


Also, these radio buttons are the circular dots. I can't remember if I made them as Form controls (I think this is right) or ActiveX.
~Kitsu
 
I figured this out on my own and wanted to share how I did it so others can possibly benefit in the future.

The below example is a simple message box that will return the values you want based on whichever radio button is selected. The radio buttons are ActiveX objects that I named "Monthly" and "Weekly".

Enjoy!

Code:
Sub execute()

Dim myRange As String

    If ActiveSheet.Monthly.Value = True Then
        myRange = "Monthly"
    ElseIf ActiveSheet.Weekly.Value = True Then
        myRange = "Weekly"
    End If
    
If myRange = "Monthly" Then MsgBox "The Range is from " & ActiveSheet.Range("B2").Value & " to " & ActiveSheet.Range("C2").Value, vbOKOnly
If myRange = "Weekly" Then MsgBox "The Range is from " & ActiveSheet.Range("B3").Value & " to " & ActiveSheet.Range("C3").Value, vbOKOnly
End Sub

RadioButtons.JPG
 
Back
Top