我一直在寻找解决方案几个小时,有人可以帮助我吗?
我有一个cmd按钮来打开用户表单并在“主查询日志”工作表中创建一个新条目。我希望cmd按钮将下一个数字自动填充到“A”列中的主日志中,然后将该数字返回给用户表单。
我认为可能需要添加用户表单初始化子,但我不确定要输入什么。
非常感谢任何帮助
Private Sub cmdAdd_Click()
Dim iRow As Long
Dim ws As Worksheet
Set ws = Worksheets("Master Enq. Log")
'find first empty row in database
iRow = ws.Cells.Find(What:="*", SearchOrder:=xlRows, _
SearchDirection:=xlPrevious, LookIn:=xlValues).Row + 1
'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, 2).Value = Me.txtCustName.Value
.Cells(iRow, 3).Value = Me.txtCustAddr.Value
.Cells(iRow, 4).Value = Date
.Cells(iRow, 5).Value = Me.cboProjEng.Value
.Cells(iRow, 6).Value = Me.cboDrawer.Value
.Cells(iRow, 11).Value = Me.cboSalesPers.Value
' .Protect Password:="password"
End With
'clear the data
Me.txtCustName.Value = ""
Me.txtCustAddr.Value = ""
Me.cboProjEng.Value = "Select"
Me.cboDrawer.Value = "Select"
Me.cboSalesPers.Value = "Select"
Me.txtCustName.SetFocus
End Sub