|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
问题都在案例里,希望高手解答,万分感谢!
案例.zip
(69.25 KB, 下载次数: 17)
或帮看看一下代码怎么简写,学习一下(我这屎山代码)
- Sub 数据刷新_账目统计()
- Dim i As Long
- Dim wa As Worksheet, ws As Worksheet
- Dim arr As Variant
- Set wa = Sheets("账目统计")
- Set ws = Sheets("月流水库")
- arr = ws.Range("A1:G2401").Value
- wa.Range("C3:N9") = ""
- '1月汇总
- sum = 0: sum2 = 0: sum3 = 0: sum4 = 0: sum5 = 0
- For i = 2 To 2401
- If Month(arr(i, 3)) = wa.Range("C2") And arr(i, 4) = wa.Range("B4") And arr(i, 5) = "结算进账" Then
- sum = sum + arr(i, 6): End If
- If Month(arr(i, 3)) = wa.Range("C2") And arr(i, 4) = wa.Range("B5") And arr(i, 5) = "结算进账" Then
- sum2 = sum2 + arr(i, 6): End If
- If Month(arr(i, 3)) = wa.Range("C2") And arr(i, 4) = wa.Range("B6") And arr(i, 5) = "结算进账" Then
- sum3 = sum3 + arr(i, 6): End If
- If Month(arr(i, 3)) = wa.Range("C2") And arr(i, 4) = wa.Range("B7") And arr(i, 5) = "结算进账" Then
- sum4 = sum4 + arr(i, 6): End If
- If Month(arr(i, 3)) = wa.Range("C2") And arr(i, 4) = wa.Range("B8") And arr(i, 5) = "结算进账" Then
- sum5 = sum5 + arr(i, 6): End If
- Next:
- wa.Range("C4").Value = sum
- wa.Range("C5").Value = sum2
- wa.Range("C6").Value = sum3
- wa.Range("C7").Value = sum4
- wa.Range("C8").Value = sum5
- '2月汇总
- sum = 0: sum2 = 0: sum3 = 0: sum4 = 0: sum5 = 0
- For i = 2 To 2401
- If Month(arr(i, 3)) = wa.Range("D2") And arr(i, 4) = wa.Range("B4") And arr(i, 5) = "结算进账" Then
- sum = sum + arr(i, 6): End If
- If Month(arr(i, 3)) = wa.Range("D2") And arr(i, 4) = wa.Range("B5") And arr(i, 5) = "结算进账" Then
- sum2 = sum2 + arr(i, 6): End If
- If Month(arr(i, 3)) = wa.Range("D2") And arr(i, 4) = wa.Range("B6") And arr(i, 5) = "结算进账" Then
- sum3 = sum3 + arr(i, 6): End If
- If Month(arr(i, 3)) = wa.Range("D2") And arr(i, 4) = wa.Range("B7") And arr(i, 5) = "结算进账" Then
- sum4 = sum4 + arr(i, 6): End If
- If Month(arr(i, 3)) = wa.Range("D2") And arr(i, 4) = wa.Range("B8") And arr(i, 5) = "结算进账" Then
- sum5 = sum5 + arr(i, 6): End If
- Next:
- wa.Range("D4").Value = sum
- wa.Range("D5").Value = sum2
- wa.Range("D6").Value = sum3
- wa.Range("D7").Value = sum4
- wa.Range("D8").Value = sum5
- '3月汇总
- sum = 0: sum2 = 0: sum3 = 0: sum4 = 0: sum5 = 0
- For i = 2 To 2401
- If Month(arr(i, 3)) = wa.Range("E2") And arr(i, 4) = wa.Range("B4") And arr(i, 5) = "结算进账" Then
- sum = sum + arr(i, 6): End If
- If Month(arr(i, 3)) = wa.Range("E2") And arr(i, 4) = wa.Range("B5") And arr(i, 5) = "结算进账" Then
- sum2 = sum2 + arr(i, 6): End If
- If Month(arr(i, 3)) = wa.Range("E2") And arr(i, 4) = wa.Range("B6") And arr(i, 5) = "结算进账" Then
- sum3 = sum3 + arr(i, 6): End If
- If Month(arr(i, 3)) = wa.Range("E2") And arr(i, 4) = wa.Range("B7") And arr(i, 5) = "结算进账" Then
- sum4 = sum4 + arr(i, 6): End If
- If Month(arr(i, 3)) = wa.Range("E2") And arr(i, 4) = wa.Range("B8") And arr(i, 5) = "结算进账" Then
- sum5 = sum5 + arr(i, 6): End If
- Next:
- wa.Range("E4").Value = sum
- wa.Range("E5").Value = sum2
- wa.Range("E6").Value = sum3
- wa.Range("E7").Value = sum4
- wa.Range("E8").Value = sum5
- '4月汇总
- sum = 0: sum2 = 0: sum3 = 0: sum4 = 0: sum5 = 0
- For i = 2 To 2401
- If Month(arr(i, 3)) = wa.Range("F2") And arr(i, 4) = wa.Range("B4") And arr(i, 5) = "结算进账" Then
- sum = sum + arr(i, 6): End If
- If Month(arr(i, 3)) = wa.Range("F2") And arr(i, 4) = wa.Range("B5") And arr(i, 5) = "结算进账" Then
- sum2 = sum2 + arr(i, 6): End If
- If Month(arr(i, 3)) = wa.Range("F2") And arr(i, 4) = wa.Range("B6") And arr(i, 5) = "结算进账" Then
- sum3 = sum3 + arr(i, 6): End If
- If Month(arr(i, 3)) = wa.Range("F2") And arr(i, 4) = wa.Range("B7") And arr(i, 5) = "结算进账" Then
- sum4 = sum4 + arr(i, 6): End If
- If Month(arr(i, 3)) = wa.Range("F2") And arr(i, 4) = wa.Range("B8") And arr(i, 5) = "结算进账" Then
- sum5 = sum5 + arr(i, 6): End If
- Next:
- wa.Range("F4").Value = sum
- wa.Range("F5").Value = sum2
- wa.Range("F6").Value = sum3
- wa.Range("F7").Value = sum4
- wa.Range("F8").Value = sum5
- '5月汇总
- sum = 0: sum2 = 0: sum3 = 0: sum4 = 0: sum5 = 0
- For i = 2 To 2401
- If Month(arr(i, 3)) = wa.Range("G2") And arr(i, 4) = wa.Range("B4") And arr(i, 5) = "结算进账" Then
- sum = sum + arr(i, 6): End If
- If Month(arr(i, 3)) = wa.Range("G2") And arr(i, 4) = wa.Range("B5") And arr(i, 5) = "结算进账" Then
- sum2 = sum2 + arr(i, 6): End If
- If Month(arr(i, 3)) = wa.Range("G2") And arr(i, 4) = wa.Range("B6") And arr(i, 5) = "结算进账" Then
- sum3 = sum3 + arr(i, 6): End If
- If Month(arr(i, 3)) = wa.Range("G2") And arr(i, 4) = wa.Range("B7") And arr(i, 5) = "结算进账" Then
- sum4 = sum4 + arr(i, 6): End If
- If Month(arr(i, 3)) = wa.Range("G2") And arr(i, 4) = wa.Range("B8") And arr(i, 5) = "结算进账" Then
- sum5 = sum5 + arr(i, 6): End If
- Next:
- wa.Range("G4").Value = sum
- wa.Range("G5").Value = sum2
- wa.Range("G6").Value = sum3
- wa.Range("G7").Value = sum4
- wa.Range("G8").Value = sum5
- '6月汇总
- sum = 0: sum2 = 0: sum3 = 0: sum4 = 0: sum5 = 0
- For i = 2 To 2401
- If Month(arr(i, 3)) = wa.Range("H2") And arr(i, 4) = wa.Range("B4") And arr(i, 5) = "结算进账" Then
- sum = sum + arr(i, 6): End If
- If Month(arr(i, 3)) = wa.Range("H2") And arr(i, 4) = wa.Range("B5") And arr(i, 5) = "结算进账" Then
- sum2 = sum2 + arr(i, 6): End If
- If Month(arr(i, 3)) = wa.Range("H2") And arr(i, 4) = wa.Range("B6") And arr(i, 5) = "结算进账" Then
- sum3 = sum3 + arr(i, 6): End If
- If Month(arr(i, 3)) = wa.Range("H2") And arr(i, 4) = wa.Range("B7") And arr(i, 5) = "结算进账" Then
- sum4 = sum4 + arr(i, 6): End If
- If Month(arr(i, 3)) = wa.Range("H2") And arr(i, 4) = wa.Range("B8") And arr(i, 5) = "结算进账" Then
- sum5 = sum5 + arr(i, 6): End If
- Next:
- wa.Range("H4").Value = sum
- wa.Range("H5").Value = sum2
- wa.Range("H6").Value = sum3
- wa.Range("H7").Value = sum4
- wa.Range("H8").Value = sum5
- '7月汇总
- sum = 0: sum2 = 0: sum3 = 0: sum4 = 0: sum5 = 0
- For i = 2 To 2401
- If Month(arr(i, 3)) = wa.Range("I2") And arr(i, 4) = wa.Range("B4") And arr(i, 5) = "结算进账" Then
- sum = sum + arr(i, 6): End If
- If Month(arr(i, 3)) = wa.Range("I2") And arr(i, 4) = wa.Range("B5") And arr(i, 5) = "结算进账" Then
- sum2 = sum2 + arr(i, 6): End If
- If Month(arr(i, 3)) = wa.Range("I2") And arr(i, 4) = wa.Range("B6") And arr(i, 5) = "结算进账" Then
- sum3 = sum3 + arr(i, 6): End If
- If Month(arr(i, 3)) = wa.Range("I2") And arr(i, 4) = wa.Range("B7") And arr(i, 5) = "结算进账" Then
- sum4 = sum4 + arr(i, 6): End If
- If Month(arr(i, 3)) = wa.Range("I2") And arr(i, 4) = wa.Range("B8") And arr(i, 5) = "结算进账" Then
- sum5 = sum5 + arr(i, 6): End If
- Next:
- wa.Range("I4").Value = sum
- wa.Range("I5").Value = sum2
- wa.Range("I6").Value = sum3
- wa.Range("I7").Value = sum4
- wa.Range("I8").Value = sum5
- '8月汇总
- sum = 0: sum2 = 0: sum3 = 0: sum4 = 0: sum5 = 0
- For i = 2 To 2401
- If Month(arr(i, 3)) = wa.Range("J2") And arr(i, 4) = wa.Range("B4") And arr(i, 5) = "结算进账" Then
- sum = sum + arr(i, 6): End If
- If Month(arr(i, 3)) = wa.Range("J2") And arr(i, 4) = wa.Range("B5") And arr(i, 5) = "结算进账" Then
- sum2 = sum2 + arr(i, 6): End If
- If Month(arr(i, 3)) = wa.Range("J2") And arr(i, 4) = wa.Range("B6") And arr(i, 5) = "结算进账" Then
- sum3 = sum3 + arr(i, 6): End If
- If Month(arr(i, 3)) = wa.Range("J2") And arr(i, 4) = wa.Range("B7") And arr(i, 5) = "结算进账" Then
- sum4 = sum4 + arr(i, 6): End If
- If Month(arr(i, 3)) = wa.Range("J2") And arr(i, 4) = wa.Range("B8") And arr(i, 5) = "结算进账" Then
- sum5 = sum5 + arr(i, 6): End If
- Next:
- wa.Range("J4").Value = sum
- wa.Range("J5").Value = sum2
- wa.Range("J6").Value = sum3
- wa.Range("J7").Value = sum4
- wa.Range("J8").Value = sum5
- '后面还有4个月的,发不出来了 高手给看看
- End Sub
复制代码
|
|