|
不好意思啊
改成
Option Explicit
Sub 查询()
Dim cnn As Object
Dim Sql$, f$, D, ARR, BRR, i%, j%, s$
f = Replace(ThisWorkbook.Path, "查询表", "") & "\数据源\例子.xlsx"
Set cnn = CreateObject("ADODB.CONNECTION")
Set D = CreateObject("Scripting.Dictionary")
cnn.Open "Provider=Microsoft.ACE.OleDb.12.0;Extended Properties='Excel 12.0;HDR=YES'; Data Source=" & f
Sql = "select 年份,月份,SUM(收入) from [收入$a1:h] WHERE 店铺名称='" & [E2] & "'group by 年份,月份,店铺名称 "
ARR = cnn.Execute(Sql).GETROWS
For i = 0 To UBound(ARR, 2)
s = ARR(0, i) & ARR(1, i)
D(s) = ARR(2, i)
Next
[c6:n8] = ""
BRR = [a5:n8]
For i = 2 To 4
For j = 3 To 14
s = BRR(i, 1) & BRR(1, j)
BRR(i, j) = D(s)
Next
Next
[a5].Resize(4, 14) = BRR
Sql = "select 年份,月份,SUM(成本) from [收入$a1:h] WHERE 店铺名称='" & [E2] & "'group by 年份,月份,店铺名称 "
ARR = cnn.Execute(Sql).GETROWS
For i = 0 To UBound(ARR, 2)
s = ARR(0, i) & ARR(1, i)
D(s) = ARR(2, i)
Next
[c11:n13] = ""
BRR = [a10:n13]
For i = 2 To 4
For j = 3 To 14
s = BRR(i, 1) & BRR(1, j)
BRR(i, j) = D(s)
Next
Next
[a10].Resize(4, 14) = BRR
cnn.Close: Set cnn = Nothing
End Sub
|
|