|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
重上传一份,请老大
特请老大优化一下:金额1 金额2 后面还有 金额3 金额4....,并按 111、110、101...112、113 如上面的排序,特请老大优化一下
汇总表格式 金额1 金额1号 金额2 金额2号 后面还有 金额3 金额3号....,
x = Range("M2").Value '日期
X1 = Range("M3").Value日期
y = Range("P3").Value
YY = Year(x) & Format(Month(x), "00") & "' and format(消费日期,'yyyymm') <= '" & Year(X1) & Format(Month(X1), "00")
Dim arr
Set cnn = CreateObject("adodb.connection")
cnn.Open "provider=microsoft.jet.oledb.4.0;data source =" & ThisWorkbook.path & "\系统数据库.mdb" '员工11金额11产品
SQL111 = "SELECT sum(金额1) as 金额1 FROM 营业额 where format(消费日期,'yyyyMM') >= '" & YY & "' and 金额1号 like '" & 111 & "' HAVING 金额1号 "
SQL110 = "SELECT sum(金额1) as 金额1 FROM 营业额 where format(消费日期,'yyyyMM') >= '" & YY & "' and 金额1号 like '" & 110 & "' HAVING 金额1号 "
SQL101 = "SELECT sum(金额1) as 金额1 FROM 营业额 where format(消费日期,'yyyyMM') >= '" & YY & "' and 金额1号 like '" & 101 & "' HAVING 金额1号 "
SQL102 = "SELECT sum(金额1) as 金额1 FROM 营业额 where format(消费日期,'yyyyMM') >= '" & YY & "' and 金额1号 like '" & 102 & "' HAVING 金额1号 "
SQL103 = "SELECT sum(金额1) as 金额1 FROM 营业额 where format(消费日期,'yyyyMM') >= '" & YY & "' and 金额1号 like '" & 103 & "' HAVING 金额1号 "
SQL104 = "SELECT sum(金额1) as 金额1 FROM 营业额 where format(消费日期,'yyyyMM') >= '" & YY & "' and 金额1号 like '" & 104 & "' HAVING 金额1号 "
SQL105 = "SELECT sum(金额1) as 金额1 FROM 营业额 where format(消费日期,'yyyyMM') >= '" & YY & "' and 金额1号 like '" & 105 & "' HAVING 金额1号 "
SQL106 = "SELECT sum(金额1) as 金额1 FROM 营业额 where format(消费日期,'yyyyMM') >= '" & YY & "' and 金额1号 like '" & 106 & "' HAVING 金额1号 "
SQL107 = "SELECT sum(金额1) as 金额1 FROM 营业额 where format(消费日期,'yyyyMM') >= '" & YY & "' and 金额1号 like '" & 107 & "' HAVING 金额1号 "
SQL109 = "SELECT sum(金额1) as 金额1 FROM 营业额 where format(消费日期,'yyyyMM') >= '" & YY & "' and 金额1号 like '" & 109 & "' HAVING 金额1号 "
SQL112 = "SELECT sum(金额1) as 金额1 FROM 营业额 where format(消费日期,'yyyyMM') >= '" & YY & "' and 金额1号 like '" & 112 & "' HAVING 金额1号 "
Set rs = New ADODB.Recordset
SQL = "select a.金额1,b.金额1,c.金额1,d.金额1,e.金额1,f.金额1,g.金额1,h.金额1,i.金额1,j.金额1,k.金额1 from (" & SQL111 & ") a,(" & SQL110 & ") b,(" & SQL101 & ") c,(" & SQL102 & ") d,(" & SQL103 & ") e,(" & SQL104 & ") f ,(" & SQL105 & ") g,(" & SQL106 & ") h,(" & SQL107 & ") i,(" & SQL109 & ") j,(" & SQL112 & ") k "
rs.Open SQL, cnn, adOpenKeyset, adLockOptimistic
arr = cnn.Execute(SQL).GetRows
Range("D6").Resize(UBound(arr) + 1, UBound(arr, 2) + 1) = arr '行转列保存
Set cnn = CreateObject("adodb.connection") '
cnn.Open "provider=microsoft.jet.oledb.4.0;data source =" & ThisWorkbook.path & "\系统数据库.mdb" '
SQL111 = "SELECT sum(金额2) as 金额2 FROM 营业额 where format(消费日期,'yyyyMM') >= '" & YY & "' and 金额2号 like '" & 111 & "' HAVING 金额2号 "
SQL110 = "SELECT sum(金额2) as 金额2 FROM 营业额 where format(消费日期,'yyyyMM') >= '" & YY & "' and 金额2号 like '" & 110 & "' HAVING 金额2号 "
SQL101 = "SELECT sum(金额2) as 金额2 FROM 营业额 where format(消费日期,'yyyyMM') >= '" & YY & "' and 金额2号 like '" & 101 & "' HAVING 金额2号 "
SQL102 = "SELECT sum(金额2) as 金额2 FROM 营业额 where format(消费日期,'yyyyMM') >= '" & YY & "' and 金额2号 like '" & 102 & "' HAVING 金额2号 "
SQL103 = "SELECT sum(金额2) as 金额2 FROM 营业额 where format(消费日期,'yyyyMM') >= '" & YY & "' and 金额2号 like '" & 103 & "' HAVING 金额2号 "
SQL104 = "SELECT sum(金额2) as 金额2 FROM 营业额 where format(消费日期,'yyyyMM') >= '" & YY & "' and 金额2号 like '" & 104 & "' HAVING 金额2号 "
SQL105 = "SELECT sum(金额2) as 金额2 FROM 营业额 where format(消费日期,'yyyyMM') >= '" & YY & "' and 金额2号 like '" & 105 & "' HAVING 金额2号 "
SQL106 = "SELECT sum(金额2) as 金额2 FROM 营业额 where format(消费日期,'yyyyMM') >= '" & YY & "' and 金额2号 like '" & 106 & "' HAVING 金额2号 "
SQL107 = "SELECT sum(金额2) as 金额2 FROM 营业额 where format(消费日期,'yyyyMM') >= '" & YY & "' and 金额2号 like '" & 107 & "' HAVING 金额2号 "
SQL109 = "SELECT sum(金额2) as 金额2 FROM 营业额 where format(消费日期,'yyyyMM') >= '" & YY & "' and 金额2号 like '" & 109 & "' HAVING 金额2号 "
SQL110 = "SELECT sum(金额2) as 金额2 FROM 营业额 where format(消费日期,'yyyyMM') >= '" & YY & "' and 金额2号 like '" & 110 & "' HAVING 金额2号 "
SQL112 = "SELECT sum(金额2) as 金额2 FROM 营业额 where format(消费日期,'yyyyMM') >= '" & YY & "' and 金额2号 like '" & 112 & "' HAVING 金额2号 "
Set rs = New ADODB.Recordset
SQL = "select a.金额2,b.金额2,c.金额2,d.金额2,e.金额2,f.金额2,g.金额2,h.金额2,i.金额2,j.金额2,k.金额2 from (" & SQL111 & ") a,(" & SQL110 & ") b,(" & SQL101 & ") c,(" & SQL102 & ") d,(" & SQL103 & ") e,(" & SQL104 & ") f ,(" & SQL105 & ") g,(" & SQL106 & ") h,(" & SQL107 & ") i,(" & SQL109 & ") j,(" & SQL112 & ") k "
rs.Open SQL, cnn, adOpenKeyset, adLockOptimistic
arr = cnn.Execute(SQL).GetRows
Range("E6").Resize(UBound(arr) + 1, UBound(arr, 2) + 1) = arr '行转列保存
特请老大优化一下:金额1 金额2 后面还有 金额3 金额4....,并按 111、110、101...112、113 如上面的排序,特请老大优化一下
|
|