如何从VBA表单中将选定的无线电值插入Excel电子表格?通过无线电值我们的意思是只有一种可能的选择。我很难在VBA中实现这一目标。
以下是我的无线电值:
优先级 - 位于 fr_Priority 框架中的选项,两个可能的复选框选项:
priority_y - 如果用户选择此项,则是将被插入单元格
priority_n - 如果用户选择此项,则否将插入单元格
lectureStyle - 位于框架 fr_LectureStyle 中的选项,两个可能的复选框选项:
lecturestyle_trad - 如果用户选择此项,则传统将被插入单元格
lecturestyle_sem - 如果用户选择此项,则研讨会将被插入单元格
lecturestyle_lab - 如果用户选择此项,则 Lab 将插入单元格
lecturestyle_any - 如果用户选择此项,则 Any 将被插入单元格
roomStructure - 位于框架 fr_roomStruc 中的选项,两个可能的复选框选项:
rs_Tiered - 如果用户选择此项,则分层将插入单元格
rs_Flat - 如果用户选择此项,则 Flat 将插入单元格
到目前为止,这是我的代码:
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
非常感谢你的帮助!
答案 0 :(得分:1)
对我而言,您似乎需要对收音机盒的值进行一些验证,这是您可以做到的一种方式
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