Sub Test()
Dim t As Long, x As Long, i As Long
t = Range("D4").Value
Range("L4:L8").Value = Range("K4:K8").Value
For i = 4 To 8
Range("L" & i).Value = Range("L" & i).Value - 1
If Range("L" & i).Value < 0 Then Range("L" & i).Value = 0
x = WorksheetFunction.Sum(Range("L4:L8"))
If x <= t Then Exit Sub
If i = 8 And t < x Then i = 4
Next i
End Sub
X is the name that must match with J column.Here,in above post,I have attached file where,I have mentioned the same name 'X'.This would be a matching criteria.Hi, what A4=X stands for ?
Sub DemoAX0()
A = [D4]
X = [K4:K8].Value
For R = 5 To 1 Step -1
If A Then X(R, 1) = Application.Min(X(R, 1), A): A = A - X(R, 1) Else X(R, 1) = Empty
Next
[L4:L8] = X
End Sub
make flexible in coding that can take any range