Results 1 to 2 of 2

Thread: Get Radio Button data

  1. #1
    Seeker kitsu_ne's Avatar
    Join Date
    Jan 2014
    Location
    http://www.khanacademy.org/profile/killervulpix/#programs
    Posts
    16
    Articles
    0

    Get Radio Button data



    Register for a FREE account, and/
    or Log in to avoid these ads!

    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

  2. #2
    Seeker kitsu_ne's Avatar
    Join Date
    Jan 2014
    Location
    http://www.khanacademy.org/profile/killervulpix/#programs
    Posts
    16
    Articles
    0
    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
    Click image for larger version. 

Name:	RadioButtons.JPG 
Views:	6 
Size:	32.8 KB 
ID:	2035

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •