|
就事论事,用VBA做了一个,在”数据源表“中插入一个模块,添加如下代码,然后运行”创建统计表“这个宏就好了。- Sub 创建统计表()
- Application.ScreenUpdating = False
- Dim wbk As Workbook, wstDB As Worksheet, wstRT As Worksheet, i%
- Set wbk = Workbooks.Add
- For Each wstDB In ThisWorkbook.Worksheets
- Set wstRT = wbk.Worksheets.Add
- wstRT.Name = wstDB.Name
- With wstRT
- .[A1] = "单位名称: xxxxxxxx公司"
- .[E1] = "姓名:"
- .[F1] = .Name
- .[H1] = "员工编码:"
- .[K1] = "统计年度"
- .[L1] = "2011年"
- .[A2] = "项目月份"
- For i = 1 To 12
- .Cells(2, i + 1) = i & "月"
- Next
- .[N2] = "合计"
- .[A3] = "基本工资"
- .[A4] = "津贴和补贴"
- .[A5] = "各种奖金"
- .[A6] = "加班工资"
- .[A7] = "其他"
- .[A8] = "合计"
- .[A9] = "上年度月平均工资(元)"
- .[B9] = "=ROUND(N8/12,2)"
- .[D9] = "本年度月缴费基数(元)"
- .[H9] = "本年度月缴费比例(%)"
- .[K9] = "本年度月缴费额(元)"
- .[N3:N7].FormulaR1C1 = "=SUM(RC[-12]:RC[-1])"
- .[B8:N8].FormulaR1C1 = "=SUM(R[-5]C:R[-1]C)"
- wstDB.[B2:B13].Copy '基本工资
- .[B3].PasteSpecial xlPasteValues, xlPasteSpecialOperationNone, False, True
- wstDB.[C2:C13].Copy '基本工资
- .[B3].PasteSpecial xlPasteValues, xlPasteSpecialOperationAdd, False, True
- wstDB.[D2:D13].Copy '津贴和补贴
- .[B4].PasteSpecial xlPasteValues, xlPasteSpecialOperationNone, False, True
- wstDB.[E2:E13].Copy '津贴和补贴
- .[B4].PasteSpecial xlPasteValues, xlPasteSpecialOperationAdd, False, True
- wstDB.[F2:F13].Copy '各种奖金
- .[B5].PasteSpecial xlPasteValues, xlPasteSpecialOperationNone, False, True
- wstDB.[G2:G13].Copy '各种奖金
- .[B5].PasteSpecial xlPasteValues, xlPasteSpecialOperationAdd, False, True
- wstDB.[H2:H13].Copy '各种奖金
- .[B5].PasteSpecial xlPasteValues, xlPasteSpecialOperationAdd, False, True
- wstDB.[I2:I13].Copy '加班工资
- .[B6].PasteSpecial xlPasteValues, xlPasteSpecialOperationNone, False, True
- wstDB.[J2:J13].Copy '其他
- .[B7].PasteSpecial xlPasteValues, xlPasteSpecialOperationNone, False, True
- End With
- Next
- wbk.SaveAs Filename:=ThisWorkbook.Path & "\统计表-" & Format(Now, "yyyymmddhhmmss"), FileFormat:=xlExcel5
- wbk.Close
- Set wbk = Nothing
- Set wstDB = Nothing
- Set wstRT = Nothing
- Application.CutCopyMode = False
- Application.ScreenUpdating = True
- End Sub
复制代码 |
|