Option
Explicit
Sub
Bestand()
Dim
lzBest
As
Long
, lzBewe
As
Long
, n
As
Long
, x
As
Long
Dim
wksBest
As
Worksheet, wksBewe
As
Worksheet
Dim
arrBest()
As
Variant
, arrBewe()
As
Variant
Dim
objRng
As
Range
Set
wksBest = ThisWorkbook.Worksheets(
"Bestand"
)
Set
wksBewe = ThisWorkbook.Worksheets(
"Bewegung"
)
With
wksBest
lzBest = .Cells(.Rows.Count, 1).
End
(xlUp).Row
Set
objRng = .Range(.Cells(2, 1), .Cells(lzBest, 3))
arrBest = objRng.Value
End
With
With
wksBewe
lzBewe = .Cells(.Rows.Count, 1).
End
(xlUp).Row
Set
objRng = .Range(.Cells(2, 1), .Cells(lzBewe, 3))
arrBewe = objRng.Value
End
With
For
n = 1
To
UBound(arrBewe)
For
x = 1
To
UBound(arrBest)
If
arrBewe(n, 1) = arrBest(x, 1)
Then
arrBest(x, 3) = arrBest(x, 3) + arrBewe(n, 3)
arrBewe(n, 3) = 0
Exit
For
End
If
Next
x
Next
n
wksBest.Cells(2, 1).Resize(UBound(arrBest, 1), UBound(arrBest, 2)).Value = arrBest
wksBewe.Cells(2, 1).Resize(UBound(arrBewe, 1), UBound(arrBewe, 2)).Value = arrBewe
End
Sub