|
代码如下。。。。
Sub test1()
Set cnn = CreateObject("ADODB.Connection")
Set rst = CreateObject("ADODB.Recordset")
strSQL = "provider=Microsoft.ACE.OLEDB.12.0;data source=" & _
ThisWorkbook.Path & "\HXDataBase.accdb"
cnn.Open strSQL
s = Join(Application.Rept(Sheets("Sheet3").[g1:i1], 1), ",")
s1 = s & ",sum(" & Sheets("Sheet3").[j1] & ") as " & Sheets("Sheet3").[j1]
sql = "Select " & s1 & " from 产品参数 group by " & s
rst.Open sql, cnn, 1, 1
Sheets("Sheet3").[g2].CopyFromRecordset rst
rst.Close
cnn.Close
Set rst = Nothing
Set cnn = Nothing
Beep
End Sub
|
|