1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
| Sub Transfert()
Dim N As Long, M As Long, i As Long, j As Long
Dim BL As Variant, STK As Variant
Application.ScreenUpdating = False
With Worksheets("saisie BL")
N = .Cells(.Rows.Count, "A").End(xlUp).Row
BL = .Range("A2:B" & N).Value
With Worksheets("état de stock")
M = .Cells(.Rows.Count, "A").End(xlUp).Row
STK = .Range("A2:C" & M).Value
Stocker BL, STK
.Range("A2:C" & M).Value = STK
End With
.Range("A2:B" & N).Value = BL
End With
End Sub
Private Sub Stocker(Tb As Variant, Res As Variant)
Dim N As Long, M As Long, i As Long, j As Long
N = UBound(Tb, 1)
M = UBound(Res, 1)
Do
i = i + 1
If Tb(i, 2) > 0 Then
For j = 1 To M
If Res(j, 2) > 0 Then
If Tb(i, 1) = Res(j, 1) Then
If Res(j, 2) >= Tb(i, 2) Then
Res(j, 2) = Res(j, 2) - Tb(i, 2)
Tb(i, 2) = 0
Exit For
Else
Tb(i, 2) = Tb(i, 2) - Res(j, 2)
Res(j, 2) = 0
i = i - 1
Exit For
End If
End If
End If
Next j
End If
Loop While i < N
End Sub |
Partager