0

選択したラジオの値を VBA フォームから Excel スプレッドシートに挿入するにはどうすればよいですか? 無線値とは、可能なオプションが 1 つしかないことを意味します。VBAでこれを達成するのに苦労しています。


ここに私の無線値があります:

優先度 - フレームfr_Priorityにあるオプション。2 つの可能なチェックボックス オプション:

  • priority_y - ユーザーがこれを選択すると、はいがセルに挿入されます

  • priority_n - ユーザーがこれを選択すると、 Noがセルに挿入されます

lectureStyle - フレームfr_LectureStyleにあるオプション。2 つの可能なチェックボックス オプション:

  • Lecturestyle_trad - ユーザーがこれを選択すると、トラディショナルがセルに挿入されます

  • lecturestyle_sem - ユーザーがこれを選択すると、セミナーがセルに挿入されます

  • lecturestyle_lab - ユーザーがこれを選択すると、ラボがセルに挿入されます

  • lecturestyle_any - ユーザーがこれを選択すると、 Anyがセルに挿入されます

roomStructure - フレームfr_roomStrucにあるオプション。2 つの可能なチェックボックス オプション:

  • rs_Tiered - ユーザーがこれを選択すると、 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

助けてくれてどうもありがとう!

4

1 に答える 1

1

私には、ラジオボックスの値を検証する必要があるように思えます。これを行う方法の 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

于 2012-10-30T12:30:04.400 に答える