|
Sub ADO法()
Dim cnn As Object, rs As Object, SQL$, i&
Set cnn = CreateObject("ADODB.Connection")
cnn.Open "provider=microsoft.ace.oledb.12.0;extended properties='excel 12.0;HDR=yes;imex=3';data source=" & ThisWorkbook.FullName
SQL = "TRANSFORM SUM(实际成本发生额) SELECT 成本要素,成本要素描述,SUM(实际成本发生额) AS 合计 FROM [Sheet1$a1:i] GROUP BY 成本要素,成本要素描述 PIVOT 部门"
Set rs = cnn.Execute(SQL)
With Sheets("结果")
.Cells.ClearContents
For i = 0 To rs.Fields.Count - 1
.Cells(1, i + 1) = rs.Fields(i).Name
Next
.Range("A2").CopyFromRecordset rs
End With
rs.Close
cnn.Close
Set rs = Nothing
Set cnn = Nothing
End Sub |
评分
-
1
查看全部评分
-
|