Advertisement
YasserKhalil2019

FB_Decrease Value In Worksheet Change Event

Feb 22nd, 2020
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. https://excel-egy.com/forum/f33
  2. -------------------------------
  3.  
  4. Private Sub Worksheet_Change(ByVal Target As Range)
  5. Dim v As Double, x As Double, c As Long
  6.  
  7. If Target.CountLarge > 1 Then Exit Sub
  8.  
  9. If Target.Column = 8 Then
  10. Application.ScreenUpdating = False
  11. v = Val(Target.Value)
  12. If v > 0 Then
  13. For c = 7 To 1 Step -1
  14. If v - Cells(Target.Row, c) >= 0 Then
  15. v = v - Cells(Target.Row, c)
  16. x = x + Cells(Target.Row, c)
  17. Cells(Target.Row, c) = 0
  18. End If
  19. If v = 0 Or c = 1 Then Target.Value = Target.Value - x: Exit For
  20. Next c
  21. End If
  22. Application.ScreenUpdating = True
  23. End If
  24. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement