|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
不说了,直接上图了,提示溢出,也在坛子里看了一些资料,但没有解决实问题,请大神指点,下面是代码:
Private Sub CommandButton6_Click()
Dim conn As Object
Dim arr, brr
Dim sql1$, sql2$, sql3$, sql4$
Set conn = CreateObject("adodb.connection")
conn.Open "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & ThisWorkbook.Path & "\2016SX.xlsx" & ";Extended Properties=""Excel 12.0;HDR=YES"";"""
sql1 = "select 档口,IIF(金额/数量>=300,数量*1,数量/2) AS SL,数量,金额,月,日 FROM [销售$] where ( 类型='00' OR 类型='01') AND 档口<>'L01' AND 档口<>'LA' "
sql2 = "select b.档口,a.SL,a.数量,a.金额,a.月,a.日,b.DXS,b.任务,B.店属 FROM (" & sql1 & ")a LEFT join [excel 8.0;database=" & ThisWorkbook.Path & "\操作.XLSM].[任务设置$]b on a.档口=b.档口 and a.月=b.月"
sql3 = "select C.档口,C.地区,C.卡号,C.租金,D.任务,D.店属,D.数量,D.金额,D.SL,D.DXS,D.月,D.日 FROM (" & sql2 & ")D LEFT join [excel 8.0;database=" & ThisWorkbook.Path & "\2016JC.xlsx].[店面$]C on D.档口=C.档口"
sql4 = "transform sum(SL) select 月,卡号,档口,店属,地区,AVG(DXS),ROUND(sum(SL)/AVG(DXS),1),round(SUM(金额)/SUM(数量),0),sum(金额)/10000,AVG(租金),AVG(任务),round(sum(SL),1),iif(AVG(任务)=0,0,sum(SL)/AVG(任务)) From (" & sql3 & ") group by 月,卡号,档口,店属,地区 pivot 日"
Range("b5").CopyFromRecordset conn.Execute(sql4)
conn.Close
Set conn = Nothing
End Sub
|
|