在工资表工作表中加一个ActiveX命令按钮双击后编写如下代码
Private Sub CommandButton1_Click()
Dim n As Integer
Dim i As Integer
n = Sheets("工资表").[a1].CurrentRegion.Rows.Count
Sheets("工资表").[a1].CurrentRegion.Copy Sheets("工资条").[a1]
For i = 3 To (n - 2) * 2
If Sheets("工资条").Cells(i, 1) <> "" Then
Sheets("工资条").Rows(i + 1).Insert
End If
If Sheets("工资条").Cells(i, 1) = "" Then
Sheets("工资条").[A2:I2].Copy Sheets("工资条").Cells(i, 1)
End If
Next i
End Sub
备注:此源码来自本人自行编写《EXCEL VBA+Access开发》课程教学讲义。
[此贴子已经被作者于2007-5-17 11:19:12编辑过]
|