0

機能する Excel フォームがあり、データを 1 つのワークシートに保存します。私はラジオボタンを配置できるようにしたいと思っており、その選択に基づいて別のワークシートに保存したいと思っています。例: ラジオ ボタン 1 が選択されている場合、シート 1 に保存 ラジオ ボタン 2 が選択されている場合、シート 2 に保存 ラジオ ボタン 3 が選択されている場合、シート 3 に保存

別のワークシートに保存するために使用される同じフォーム。

使用しているコード。

Private Sub btn_append_Click()

Dim iRow As Long
Dim ws As Worksheet
Set ws = Worksheets("Assessment")

'find first empty row in database
iRow = ws.Cells.Find(What:="*", SearchOrder:=xlRows, _
    SearchDirection:=xlPrevious, LookIn:=xlValues).Row + 1

'check for a part number
If Trim(Me.txt_roomNumber.Value) = "" Then
  Me.txt_roomNumber.SetFocus
  MsgBox "Please enter a Room Number"
  Exit Sub
End If

'copy the data to the database
'use protect and unprotect lines,
'     with your password
'     if worksheet is protected
With ws
'  .Unprotect Password:="password"
  .Cells(iRow, 1).Value = Me.txt_roomNumber.Value
  .Cells(iRow, 2).Value = Me.txt_roomName.Value
  .Cells(iRow, 3).Value = Me.txt_department.Value
  .Cells(iRow, 4).Value = Me.txt_contact.Value
  .Cells(iRow, 5).Value = Me.txt_altContact.Value
  .Cells(iRow, 6).Value = Me.cbx_devices.Value
  .Cells(iRow, 7).Value = Me.cbx_wallWow.Value
  .Cells(iRow, 8).Value = Me.txt_existingHostName.Value
  .Cells(iRow, 10).Value = Me.cbx_relocate.Value
  If Me.ckb_powerbar.Value = True Then Cells(iRow, 11).Value = "Y"
  If Me.ckb_dataJackPull.Value = True Then Cells(iRow, 12).Value = "P"
  .Cells(iRow, 13).Value = Me.txt_existingDataJack.Value
  If Me.ckb_hydroPull.Value = True Then Cells(iRow, 14).Value = "P" Else Cells(iRow, 14).Value = "A"
  .Cells(iRow, 19).Value = Me.txt_cablePullDesc.Value
  .Cells(iRow, 20).Value = Me.txt_hydroPullDesc.Value
  .Cells(iRow, 21).Value = Me.Txt_otherDesc.Value
'  .Protect Password:="password"
End With

'clear the data
'Me.txt_roomNumber.Value = ""
'Me.txt_roomName.Value = ""
'Me.txt_department.Value = ""
'Me.txt_contact.Value = ""
'Me.txt_altContact.Value = ""
Me.cbx_relocate.Value = ""
Me.txt_existingHostName = ""
Me.txt_altContact.SetFocus

End Sub

Private Sub btn_close_Click()
 Unload Me
End Sub

Private Sub ComboBox1_Change()

End Sub

Private Sub UserForm_Click()

End Sub

Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
 If CloseMode = vbFormControlMenu Then
    Cancel = True
    MsgBox "Please use the Close Form button!"
  End If
End Sub
4

1 に答える 1

0

最初に行うことは、ラジオボタン (実際にはOptionButton) をフォームに追加して名前を付けることです。

次に、それらのいずれかが選択されているかどうかを確認するには、次のようなコードを使用します。

If optSheet1 Then
    'it is checked
ElseIf optSheet2 Then
    'the second one is checked
'etc
End If
于 2013-07-03T18:07:28.817 に答える