|
Sub DoCnn()
Dim cnn As Object, s$
Set cnn = CreateObject("adodb.connection")
cnn.Open "provider=microsoft.ace.oledb.12.0;extended properties=excel 12.0;data source=" & ThisWorkbook.FullName
s = "select sum(重量) from (select a.品名,a.重量,a.月份,b.分类 from [sheet1$a2:d]a left join [sheet1$e2:g]b on a.品名=b.品名)"
s1 = s & " where 分类='水果'"
s2 = s & " where 月份='1月'"
[a1:b1] = Array("水果重量", "水果蔬菜1月份总重量")
Range("a2").CopyFromRecordset cnn.Execute(s1)
Range("b2").CopyFromRecordset cnn.Execute(s2)
cnn.Close
Set cnn = Nothing
End Sub |
|