Sub kerting()
Dim r%, arr, brr, i%, j%
Application.ScreenUpdating = False
With Sheets("用量登记")
If Not IsNumeric(.[b2].Value) Or Not IsNumeric(.[b3].Value) Then
MsgBox ("日期输入错误")
Exit Sub
End If
r = .Cells(.Rows.Count, 2).End(3).Row
arr = .Range("b5:c" & r)
For Each sht In ThisWorkbook.Worksheets
If sht.Name <> "用量登记" And sht.Name Like "*月" Then
If sht.Name = .[b2] & "月" Then
r1 = sht.Cells(.Rows.Count, 2).End(3).Row
brr = sht.Range("b4:w" & r1)
sht.Select
Exit For
End If
End If
Next
For i = 1 To UBound(arr)
For j = 1 To UBound(brr)
If arr(i, 1) = brr(j, 1) Then
brr(j, .[b3] + 1) = brr(j, .[b3] + 1) + arr(i, 2)
End If
Next
Next
ActiveSheet.[b4].Resize(UBound(brr), UBound(brr, 2)) = brr
ActiveSheet.Cells(3, .[b3] + 2) = .[b3].Value
End With
Erase arr
Erase brr
Application.ScreenUpdating = True
End Sub
复制进去直接累计加,即每日多次领用,在当日中累计添加就可以了,不用另外做到第二张表格。