Reputation: 125
I have a worksheet in excel where i need to perform subtraction only either of the column contains value and result should be stored in a cell automatically for each cell. for eg strong text
**JobExpense Advance Balance
4500 100 4400
8000 4000 4000
9800 5000 4800**
consider this as my sheet I need to store the contents of Balance columns automatically when user enters value in Advance columns. any help is appreciable. formula,vbscipt whatever. I have tried formula,but it will always show zeros whenever formulas are used in the columns
Upvotes: 0
Views: 159
Reputation: 1975
The below code is provided assuming that the Job Expense is ColumnA,Advance in columnB and Balance in ColumnC.
The below code will work when any change occurs in ColumnB cells.
Copy the below code and do right click on sheet tab and select view code and paste it.
Close the VBA window (Alt+Q to close VBA window) and return to that sheet and check.
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column = 2 Then
Application.EnableEvents = False
With Target
.Offset(, 1).Value = Val(.Offset(, -1).Value) - Val(.Value)
End With
Application.EnableEvents = True
End If
End Sub
Upvotes: 1