|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
Sub tt()
Cells.Clear
Set CN = CreateObject("adodb.connection")
Set RS = CreateObject("adodb.recordset")
CN.Open "provider=microsoft.jet.oledb.4.0;extended properties=excel 8.0;data source= " & ThisWorkbook.FullName
Sql = "TRANSFORM SUM(实缴金额) SELECT 纳税人名称,null as 合计 FROM [数据$] GROUP BY 纳税人名称 PIVOT( 征收项目)"
RS.Open Sql, CN, 1, 3
For I = 0 To RS.FIELDs.Count - 1
X = RS.FIELDs.Count - 1
Cells(1, 1 + I) = RS.FIELDs(I).Name
Next
Range("A2").CopyFromRecordset CN.Execute(Sql)
LASTROW = [A65536].End(3).Row
LASTCOL = [IV1].End(xlToLeft).Column
For J = 2 To LASTROW
Cells(J, 2) = Application.Sum(Cells(J, 2).Offset(, 1).Resize(, LASTCOL - 2))
Range("A1").CurrentRegion.Borders.ColorIndex = 7
Next
End Sub |
|