|
Dim cnn As New ADODB.Connection
Dim rc As ADODB.Recordset
Dim Sql As String
cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Extended Properties='Excel 8.0;Hdr=Yes';Data Source=" & ThisWorkbook.FullName
Sql = "transform sum(金额) select 姓名 from [新增数据$] group by 姓名 pivot 类型"
Set rc = cnn.Execute(Sql)
Sheets("结果数据").[A3].CopyFromRecordset rc
Sql = "select 姓名,null,油费,话费,差旅 from [初始数据$]"
Set rc = cnn.Execute(Sql)
Sheets("结果数据").[A65536].End(xlUp).Offset(1, 0).CopyFromRecordset rc
以上语句调试正常,我也是用union all 出错想出的笨办法,还望老师完善! |
|