|
Sub a()
Dim cnn, rs As Object, Sql As String, i, j
Cells.Clear
Set cnn = CreateObject("adodb.connection")
Set rs = CreateObject("adodb.Recordset")
cnn.Open "provider=microsoft.ace.oledb.12.0;extended properties=excel 12.0;data source=" & ThisWorkbook.FullName
Sql = "transform sum(订单) select 年 from [数据$] where 年 is not null group by 年 pivot 月"
rs.Open Sql, cnn, 1, 1
For i = 0 To rs.Fields.Count - 1
Cells(2, i + 1) = rs.Fields(i).Name
Next
Range("a3").CopyFromRecordset rs
Range("a3").Offset(rs.RecordCount) = "合计"
Range("a2").Offset(0, i) = "总计"
For j = 1 To rs.RecordCount
Cells(j + 2, i + 1) = "=SUM(RC[-" & i - 1 & "]:RC[-1])"
Next
For j = 2 To i + 1
Cells(rs.RecordCount + 3, j) = "=SUM(R[-" & rs.RecordCount & "]C:R[-1]C)"
Next
rs.Close
cnn.Close
Set rs = Nothing
Set cnn = Nothing
End Sub
|
评分
-
2
查看全部评分
-
|