Private Sub Worksheet_Change(ByVal Target As Range)
Dim cD As Long, cE As Long, cF As Long, Ind As Long, sixP As Long
Application.EnableEvents = False
If Not Intersect(Target, Range("H7:I18")) Is Nothing And Target.Count = 1 And Target.Value <> 0 Then
cD = Range("D" & Target.Row).Value
cE = Range("E" & Target.Row).Value
cF = Range("F" & Target.Row).Value
Select Case Target.Column
Case 8
sixP = Range("H" & Target.Row).Value
cE = cE - sixP
If cE < 0 And cD >= WorksheetFunction.RoundUp(Abs((cE * 6) / 24), 0) Then
cD = cD - WorksheetFunction.RoundUp(Abs((cE * 6) / 24), 0)
cE = cE + WorksheetFunction.RoundUp(Abs((cE * 6) / 24), 0) * 4
Else
cE = cE + (cD * 4)
cD = cD - cD
If cE < 0 And cF >= Abs(cE * 6) Then
cF = cF - Abs(cE * 6)
cE = cE + Abs(cE)
End If
End If
Case 9
Ind = Range("I" & Target.Row).Value
cF = cF - Ind
If cF < 0 And cE >= WorksheetFunction.RoundUp(Abs(cF / 6), 0) Then
cE = cE - WorksheetFunction.RoundUp(Abs(cF / 6), 0)
cF = cF + WorksheetFunction.RoundUp(Abs(cF / 6), 0) * 6
ElseIf cE < WorksheetFunction.RoundUp(Abs(cF / 6), 0) And (cD * 24) >= Abs(cF) Then
cD = cD - WorksheetFunction.RoundUp(Abs(cF / 24), 0)
cE = cE + (WorksheetFunction.RoundUp(Abs(cF / 24), 0) * 24) / 6
cE = cE - WorksheetFunction.RoundUp(Abs(cF / 6), 0)
cF = cF + WorksheetFunction.RoundUp(Abs(cF / 6), 0) * 6
Else
cF = cF + (cE * 6) + (cD * 24)
cE = cE - cE
cD = cD - cD
End If
End Select
Range("D" & Target.Row).Value = cD
Range("E" & Target.Row).Value = cE
Range("F" & Target.Row).Value = cF
End If
Application.EnableEvents = True
End Sub