Reputation: 13216
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:
priority_y - If user selects this then Yes is inserted into cell
priority_n - If user selects this then No is inserted into cell
lectureStyle - options located in the frame fr_LectureStyle, two possible checkbox options:
lecturestyle_trad - If user selects this then Traditional is inserted into cell
lecturestyle_sem - If user selects this then Seminar is inserted into cell
lecturestyle_lab - If user selects this then Lab is inserted into cell
lecturestyle_any - If user selects this then Any is inserted into cell
roomStructure - options located in the frame fr_roomStruc, two possible checkbox options:
rs_Tiered - If user selects this then Tiered is inserted into cell
rs_Flat - If user selects this then Flat is inserted into cell
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
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