methuselah
methuselah

Reputation: 13216

Insert radio values from VBA form into Excel spreadsheet

How do you insert selected radio values into a Excel spreadsheet from a VBA form? By radio values we mean that there only one possible option. I'm struggling to achieve this in VBA.


Here are my radio values:

priority - options located in the frame fr_Priority, two possible checkbox options:

lectureStyle - options located in the frame fr_LectureStyle, two possible checkbox options:

roomStructure - options located in the frame fr_roomStruc, two possible checkbox options:


Here is my code so far:

Private Sub btnSubmit_Click()
Dim ws As Worksheet, rng1 As Range
Set ws = Worksheets("main")

' Get last empty cell in column A
  Set rng1 = ws.Cells(Rows.Count, "a").End(xlUp)

' I'm strugging to insert the radio values inserted at this point, they 
' need to go into the cells specified below

' rng1.Offset(1, 10) = priority
' rng1.Offset(1, 11) = lectureStyle
' rng1.Offset(1, 12) = roomStructure

End Sub

Thanks so much for the help!

Upvotes: 0

Views: 239

Answers (1)

Francis Dean
Francis Dean

Reputation: 2476

To me it just seems like you need to do some validation on your radio box's values, here is one way you could do it

Private Sub btnSubmit_Click()

    Dim ws As Worksheet, rng1 As Range
    Set ws = Worksheets("main")

    'Get last empty cell in column A
    Set rng1 = ws.Cells(Rows.Count, "a").End(xlUp)

    ' I'm strugging to insert the radio values inserted at this point, they
    ' need to go into the cells specified below

    rng1.Offset(1, 10) = GetPriority

End Sub
Private Function GetPriority() As String

    Dim priority As String
    If Me.priority_y.Value = True Then
        priority = "Yes"
    ElseIf Me.priority_n.Value = True Then
        priority = "No"
    Else
        priority = "N/A"
    End If
    GetPriority = priority

End Function

Upvotes: 1

Related Questions