|
- Sub datatransform()
- Dim cnn As Object, sql As String, rst As Object
- Dim i As Integer, field
- Set cnn = CreateObject("adodb.connection")
- Set rst = CreateObject("adodb.recordset")
- Sheets(1).Cells.Clear
- cnn.Open "provider=microsoft.jet.oledb.4.0;extended properties='excel 8.0;hdr=no';data source=" & ThisWorkbook.FullName
- sql = "transform sum(f4) select f1 from [sheet2$] group by f1 pivot f2 "
- rst.Open sql, cnn, 1, 3
- For i = 1 To rst.fields.Count - 1
- Sheets(1).[a1].Offset(0, i) = rst.fields(i).Name
- Next
- Sheets(1).[a2].CopyFromRecordset rst
- cnn.Close: Set cnn = Nothing
- End Sub
复制代码 |
|