|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
- Sub Main()
- Dim Qichu, Ruku, Chuku
- Dim d As New Dictionary
- Dim date1 As Date, date2 As Date
- Dim ar, Code, i, j, k
- Qichu = Sheet1.Range("a3:j" & 14)
- Ruku = Sheet2.Range("a2:m" & 14)
- Chuku = Sheet3.Range("a2:m" & 14)
- date1 = Sheet4.Range("c4").Value
- date2 = Sheet4.Range("d4").Value
- ReDim ar(1 To UBound(Qichu), 1 To 14)
-
- For i = 1 To UBound(Qichu)
- Code = Qichu(i, 1)
- d.Add Code, i
- ar(i, 1) = i
- ar(i, 2) = Code
- ar(i, 3) = Qichu(i, 2)
- ar(i, 4) = Qichu(i, 3)
- ar(i, 5) = Qichu(i, 4)
- ar(i, 6) = Qichu(i, 8)
- ar(i, 7) = Qichu(i, 9)
- Next
- For i = 2 To UBound(Ruku)
- If Ruku(i, 1) >= date1 And Ruku(i, 1) < date2 Then
- Code = Ruku(i, 5)
- If d.Exists(Code) Then
- j = d(Code)
- ar(j, 8) = ar(j, 8) + Ruku(i, 11)
- ar(j, 9) = ar(j, 9) + Ruku(i, 12)
- End If
- End If
- Next
- For i = 2 To UBound(Chuku)
- If Chuku(i, 1) >= date1 And Chuku(i, 1) < date2 Then
- Code = Chuku(i, 5)
- If d.Exists(Code) Then
- j = d(Code)
- ar(j, 10) = ar(j, 10) + Chuku(i, 11)
- ar(j, 11) = ar(j, 11) + Chuku(i, 12)
- ar(j, 14) = ar(j, 14) + Chuku(i, 12) - Chuku(i, 11) * Qichu(j, 5)
- End If
- End If
- Next
- For i = 1 To d.Count
- ar(i, 12) = ar(i, 6) + ar(i, 8) - ar(i, 10)
- ar(i, 13) = ar(i, 7) + ar(i, 9) - ar(i, 11)
- Next
- With Sheet4.Range("a7")
- .Resize(999, 14).ClearContents
- .Resize(i - 1, 14).Value = ar
- .Activate
- End With
- End Sub
复制代码 |
|