YasserKhalil
Well-Known Member
Hello experts
I have a code in worksheet change
I type a number in B2 and it is supposed to distribute this number to specific categories
If I typed 1.45 I got 1 in category 1 and 2 in category 0.2
The expected output is 1 in category 1 & 3 in category 0.15
Thanks advanced for help
I have a code in worksheet change
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim Amount As Double, I As Integer
If Target.Address = "$B$2" Then
Amount = Range("B2").Value
Range("B5:B16").Value = ""
For I = 5 To 8
Do While Amount >= Cells(I, 1).Value
Cells(I, 2).Value = Cells(I, 2).Value + 1
Amount = Amount - Cells(I, 1).Value
Loop
Next I
End If
End Sub
I type a number in B2 and it is supposed to distribute this number to specific categories
If I typed 1.45 I got 1 in category 1 and 2 in category 0.2
The expected output is 1 in category 1 & 3 in category 0.15
Thanks advanced for help