【发布时间】:2018-04-10 05:38:51
【问题描述】:
我创建了一个用户表单,用于将新数据输入到工作表中。表单通过工作表顶部的 FormControlButton 加载。但是,我想将 FormControlButton 放在不同的工作表上,并从该工作表完成用户表单。当我从不同的工作表(当数据集在工作表 12 中时说工作表 11)将数据输入用户表单时,用户表单不会输入新数据。
这是用户窗体上输入按钮的代码:
Dim currentrow As Long
Private Sub CommandButton2_Click()
Dim lastrow
Dim myfname As String
lastrow = Sheet11.Range("A" & Rows.Count).End(xlUp).row
myfname = Me.Reg8.Value
For currentrow = 2 To lastrow
If Cells(currentrow, 1).Text = myfname Then
Cells(currentrow, 68).Value = Me.Reg10.Value
Cells(currentrow, 69).Value = Me.Reg11.Value
Cells(currentrow, 10).Value = Me.Reg5.Value
Cells(currentrow, 9).Value = Me.Reg6.Value
Cells(currentrow, 70).Value = Me.Reg7.Value
End If
Next
If MsgBox("Information has" & vbNewLine & "been updated") = vbOK Then
Unload Me
Sheet1.Select
End If
End Sub
我正在尝试将数据从 Sheet1 输入到 Sheet11。 提前致谢!
【问题讨论】:
标签: vba excel userform worksheet