Good day,
I am interestes in a formula or VBA code that can make the minus (-) between numbers in same cell.
In order to be more specific I will explain exactly what I want.
In cell A1 I will put a value (total no. of miles) at the begining, lets say 3000, than every day the no. of miles will decrease by a different values.
I want in the 1st day to type 2766 in cell A1 and to appear in cell B1 the diferrence 3000-2766= 234.
2nd day I will type 2501 in cell A1 and in B1 to appear the difference from the miles I did from day 1 to day 2 ... 2766-2501=265
3rd day I will type 2389 in cell A1 and in B1 to appear the difference from the miles i did from day 2 to day 3 .... 2501-2389=112
And so on.
At the moment I am using a VBA code In order to add the numbers but I need also one VBA code to substract the numbers. I will paste down the code for adding the numbers:
Private Sub Worksheet_Change (ByVal Target as Range)
If Not Application.Intersect(Range("A1"), Range(Target.Address)) Is Nothing Then
If Target.HasFormula = True Then Exit Sub
If Target.Value <> " " Then
Target.Offset(0,10).Value = Target.Offset(0,10).Value & " " & Target.Value
End If
End If
End Sub
And Module 1:
Function SumNums(pWorkRng As Range, Optional xDelim As String = " ") As Double
Dim arr As Variant
Dim xIndex As Long
arr = Split(pWorkRng, xDelim)
For xIndex = LBound(arr) To UBound(arr) Step 1
SumNums = SumNums + VBA.Val(arr(xIndex))
Next
End Function
Thank you for taking the time to read my post.
I am interestes in a formula or VBA code that can make the minus (-) between numbers in same cell.
In order to be more specific I will explain exactly what I want.
In cell A1 I will put a value (total no. of miles) at the begining, lets say 3000, than every day the no. of miles will decrease by a different values.
I want in the 1st day to type 2766 in cell A1 and to appear in cell B1 the diferrence 3000-2766= 234.
2nd day I will type 2501 in cell A1 and in B1 to appear the difference from the miles I did from day 1 to day 2 ... 2766-2501=265
3rd day I will type 2389 in cell A1 and in B1 to appear the difference from the miles i did from day 2 to day 3 .... 2501-2389=112
And so on.
At the moment I am using a VBA code In order to add the numbers but I need also one VBA code to substract the numbers. I will paste down the code for adding the numbers:
Private Sub Worksheet_Change (ByVal Target as Range)
If Not Application.Intersect(Range("A1"), Range(Target.Address)) Is Nothing Then
If Target.HasFormula = True Then Exit Sub
If Target.Value <> " " Then
Target.Offset(0,10).Value = Target.Offset(0,10).Value & " " & Target.Value
End If
End If
End Sub
And Module 1:
Function SumNums(pWorkRng As Range, Optional xDelim As String = " ") As Double
Dim arr As Variant
Dim xIndex As Long
arr = Split(pWorkRng, xDelim)
For xIndex = LBound(arr) To UBound(arr) Step 1
SumNums = SumNums + VBA.Val(arr(xIndex))
Next
End Function
Thank you for taking the time to read my post.