|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
求助:收入情况表合并过程中,如何绕开合并单元格项目,只对数字进行自动合并汇总,求大神指点代码如何修改!合并单元格的数据源表格如图:
附代码和附件:
Sub 按钮1_Click()
Dim Dx As New 类1, sql4$, sqlz$, sqll$, p$, f$, pa$, b As Boolean
Dim dd As Object, arr4(1 To 10000, 1 To 13), i&, n&, j&, k&, m&
Set dd = CreateObject("Scripting.Dictionary")
p = ThisWorkbook.Path & "\": pa = ThisWorkbook.FullName
f = Dir(p & "*.xls*")
Do While f <> ""
If p & f = pa Then GoTo 100
If Not b Then
sql4 = "select * from [" & p & f & "].[收入情况表$a4:M]"
b = True
Else
sql4 = sql4 & " union all select * from [" & p & f & "].[收入情况表$a4:M]"
End If
100 f = Dir
Loop
Drr = Dx.筛选结果(pa, sql4)
For i = 0 To UBound(Drr, 2)
If Not dd.exists(Drr(0, i)) Then
n = n + 1
dd(Drr(0, i)) = n
For j = 2 To 13
arr4(n, j) = Drr(j - 1, i)
Next
Else
m = dd(Drr(0, i))
arr4(m, 3) = arr4(m, 3) + Drr(2, i)
arr4(m, 4) = arr4(m, 4) + Drr(3, i)
arr4(m, 5) = arr4(m, 5) + Drr(4, i)
arr4(m, 7) = arr4(m, 7) + Drr(6, i)
arr4(m, 8) = arr4(m, 8) + Drr(7, i)
arr4(m, 9) = arr4(m, 9) + Drr(10, i)
arr4(m, 11) = arr4(m, 11) + Drr(10, i)
arr4(m, 12) = arr4(m, 12) + Drr(11, i)
arr4(m, 13) = arr4(m, 13) + Drr(12, i)
End If
Next
|
|