|
1、2
用此代码
3、拆分的工作表打印格式能不能用我附件上的? 这个你需要什么格式?这个已经按照你的附件格式填写了。还需要调整哪个地方?
Option Explicit
Sub a()
Dim sh As Worksheet
Application.DisplayAlerts = False
Application.ScreenUpdating = False
For Each sh In Sheets
If sh.Name <> "总表" Then
sh.Delete
End If
Next
Dim cnn As Object
Dim Sql As String, arr, i%, rs, BT, DBT, R%
BT = Array("序号", "一级部门", "二级部门", "工号", "姓名", "入职日期", "级别", "缴费基数", "公司缴费", "个人缴费", "合计缴费")
DBT = Array("制表:", "", "", "", "审核:", "", "", "", "审批:")
Set cnn = CreateObject("ADODB.CONNECTION")
Set rs = CreateObject("adodb.Recordset")
cnn.Open "Provider=Microsoft.ACE.OleDb.12.0;Extended Properties='Excel 12.0;HDR=YES'; Data Source=" & ThisWorkbook.FullName
Sql = "select distinct 所属公司 from [总表$p2:p] where 所属公司 is not null"
arr = cnn.Execute(Sql).getrows
For i = 0 To UBound(arr, 2)
Sql = "select 一级部门,二级部门,工号,姓名,入职日期,级别,缴费基数,公司缴费,个人缴费,合计缴费 from [总表$B2:p] " _
& "where 所属公司='" & arr(0, i) & "' AND 级别 IN ('A级','B级')"
rs.Open Sql, cnn, 1, 1
If rs.RecordCount > 0 Then
Sheets.Add AFTER:=Sheets(Sheets.Count)
ActiveSheet.Name = arr(0, i) & "-高管"
ActiveSheet.[A1] = Replace(Sheet1.[A1], "购买社保清单", "") & "在" & arr(0, i) & "公司购买社保清单_高管"
GoSub 100
rs.Close
End If
Sql = "select 一级部门,二级部门,工号,姓名,入职日期,级别,缴费基数,公司缴费,个人缴费,合计缴费 from [总表$B2:p] " _
& "where 所属公司='" & arr(0, i) & "' AND 级别 not IN ('A级','B级')"
If rs.State = 1 Then rs.Close
rs.Open Sql, cnn, 1, 1
If rs.RecordCount > 0 Then
Sheets.Add AFTER:=Sheets(Sheets.Count)
ActiveSheet.Name = arr(0, i) & "-非高管"
ActiveSheet.[A1] = Replace(Sheet1.[A1], "购买社保清单", "") & "在" & arr(0, i) & "公司购买社保清单_非高管"
GoSub 100
rs.Close
End If
Next
cnn.Close: Set cnn = Nothing
Application.DisplayAlerts = True
Application.ScreenUpdating = True
Exit Sub
100:
With ActiveSheet
.[A2].Resize(1, 11) = BT
.[a3] = 1
.[B3].CopyFromRecordset rs
If rs.RecordCount > 1 Then
.Range("A3").AutoFill Destination:=Range("A3").Resize(rs.RecordCount), Type:=xlFillSeries
End If
R = .[a9999].End(3).Row
.Range("a2:k" & R).Subtotal GroupBy:=2, Function:=xlSum, TotalList:=Array(9, 10, 11) _
, Replace:=True, SummaryBelowData:=True
.Range("A1:K1").Merge
.[A1] = Replace(Sheet1.[A1], "购买社保清单", "") & "在" & arr(0, i) & "公司购买社保清单_高管"
.Cells.HorizontalAlignment = xlCenter
.Cells.VerticalAlignment = xlCenter
R = .[B9999].End(3).Row
.Range("a2:k" & R).Borders.LineStyle = 1
.[A1].Offset(R + 1, 0).Resize(1, 9) = DBT
.Columns("A:k").EntireColumn.AutoFit
.Cells.Font.Name = "微软雅黑"
.Cells.Font.Size = 10
End With
Return
End Sub |
评分
-
1
查看全部评分
-
|