|
Sub test()
Dim cnn As Object
Dim rs As Object
Dim MySQL As String
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
MySQL = "SELECT 编号,'W' AS 类别, MAX(W) As PP1 FROM [PP1$] GROUP BY 编号 Union SELECT 编号,'C' AS 类别, MAX(C) As PP1 FROM [PP1$] GROUP BY 编号 Union SELECT 编号,'S' AS 类别, MAX(S) As PP1 FROM [PP1$] GROUP BY 编号"
rs.Open MySQL, cnn, 1, 3
With Sheets("结果")
.Range("A3").CopyFromRecordset rs
For i = 0 To rs.Fields.Count - 1
.Cells(2, i + 1) = rs.Fields(i).Name
Next
End With
End Sub
|
|