主要代码
Sub add()
Dim intRow As Integer
Dim strBh As String
Sheets("员工花名册").Activate
Sheets("员工花名册").Range("A1").Select
'获取员工花名册已有数据行数
intRow = ActiveCell.CurrentRegion.Rows.Count
strBh = Cells(intRow, 1) '取得最后编号
'按规则产生新的编号
strBh = "Y" & Format(Right(strBh, 4)1, "0000")
intRow = intRow1
'将用户窗体上的数据填充到“工员花名册”的新行上
【通过窗体向工作表添加数据】Cells(intRow, 1) = strBh
Cells(intRow, 2) = txtName.Value
Cells(intRow, 3).NumberFormatLocal = "@" '设置身份证列为文本格式
Cells(intRow, 3) = txtID.Value
If optMan.Value Then
Cells(intRow, 4) = "男"
Else
Cells(intRow, 4) = "女"
End If
Cells(intRow, 5) = txtNation.Value
Cells(intRow, 6) = txtBirthday.Value
Cells(intRow, 7) = cbxEdu.Value
Cells(intRow, 8) = txtAddress.Value
Cells(intRow, 9).NumberFormatLocal = "@" '设置联系电话为文本格式
Cells(intRow, 9) = txtPhone.Value
Cells(intRow, 10) = txtDep.Value
Cells(intRow, 11) = cbxDuty.Value
Cells(intRow, 12) = cbxTitle.Value
Cells(intRow, 13) = txtStart.Value
Cells(intRow, 14) = txtEnd.Value
Cells(intRow, 15) = txtMemo.Value
End Sub