|
- Sub 每个月在一张表()
- 'On Error Resume Next '// 发生错误,自动执行下一句,就是忽略错误
- Application.ScreenUpdating = False '//关闭屏幕刷新
- Application.DisplayAlerts = False '//关闭系统提示
- t = Timer '//开始时间
- StrBT = "姓名,固定工资,绩效工资,独子费,其它,扣款,应发合计,养老保险,医疗保险,失业保险,公积金,缴税工资,代扣个税,其它扣款,扣款合计,实发合计"
- StrYF = ""
- StrSQL1 = "" '//汇成总表
- For I = 1 To 12
- For Each SH In Worksheets
- If SH.Name = I & "月" Then
- If StrYF <> "" Then StrYF = StrYF & ","
- StrYF = StrYF & Format(I, "00") & "月"
-
- If StrSQL1 <> "" Then StrSQL1 = StrSQL1 & " UNION ALL "
- StrSQL1 = StrSQL1 & "SELECT " & StrBT
- StrSQL1 = StrSQL1 & ",'" & Format(I, "00") & "月' AS 月份"
- StrSQL1 = StrSQL1 & " FROM [" & SH.Name & "$A2:P]"
- StrSQL1 = StrSQL1 & " WHERE NOT 姓名 IS NULL"
-
- Exit For
- End If
- Next
- Next
- Str_coon = "HDR=yes';Data Source =" & ThisWorkbook.FullName '//OFFICE2003,2007 通用
- StrSQL = "SELECT DISTINCT 姓名 FROM (" & StrSQL1 & ") WHERE LEN(姓名)>0"
- ARX = GET_SQL_To_Arr(StrSQL, Str_coon, False) '//不重复姓名放入二维数组
-
- BRX = Split(StrYF, ",")
- For X = 0 To UBound(ARX) '//循环每一个姓名
- Set WB = Workbooks.Add
-
- For I = 0 To UBound(BRX)
- StrSQL = "SELECT " & StrBT
- StrSQL = StrSQL & ",月份 FROM (" & StrSQL1 & ")"
- StrSQL = StrSQL & " WHERE 姓名='" & ARX(X, 0) & "'"
- StrSQL = StrSQL & " AND 月份='" & BRX(I) & "'"
-
- WB.Worksheets.Add(Before:=WB.Worksheets(1)).Name = BRX(I)
- Set SHW = WB.Worksheets(BRX(I))
- SQLARR = GET_SQL_To_Arr(StrSQL, Str_coon, True)
- SHW.Range("A1").Resize(UBound(SQLARR, 1) + 1, UBound(SQLARR, 2) + 1) = SQLARR
- Next
- WB.SaveAs Filename:=ThisWorkbook.Path & "" & ARX(X, 0) & ".XLSX"
- WB.Close True
- Next
-
-
- Application.ScreenUpdating = True '//恢复屏幕刷新
- Application.DisplayAlerts = True '//恢复系统提示
- MsgBox "一共用时:" & Format(Timer - t, "#0.0000") & " 秒", , "北极狐提示!!" '//提示所用时间
- End Sub
复制代码 |
|