Forms excel 2010:基于单选按钮选择将用户从日期保存到其他工作表
我有一个excel表格,它可以工作并将数据保存到一个工作表中。我希望能够放置一个单选按钮,并基于该选择,我希望保存到不同的工作表。 例子: 如果选择单选按钮1,则保存到图纸1 如果选择单选按钮2,则保存到图纸2 如果选择单选按钮3,则保存到图纸3 用于保存在不同工作表上的相同表单 我正在使用的代码Forms excel 2010:基于单选按钮选择将用户从日期保存到其他工作表,forms,excel,Forms,Excel,我有一个excel表格,它可以工作并将数据保存到一个工作表中。我希望能够放置一个单选按钮,并基于该选择,我希望保存到不同的工作表。 例子: 如果选择单选按钮1,则保存到图纸1 如果选择单选按钮2,则保存到图纸2 如果选择单选按钮3,则保存到图纸3 用于保存在不同工作表上的相同表单 我正在使用的代码 Private Sub btn_append_Click() Dim iRow As Long Dim ws As Worksheet Set ws = Worksheets("Assessment
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
首先要做的是将单选按钮(实际上是
OptionButton
)添加到表单中并命名它们
然后,要检查是否选择了其中一个,请使用以下代码:
If optSheet1 Then
'it is checked
ElseIf optSheet2 Then
'the second one is checked
'etc
End If