Subtract cell value from last cell before TOTAL row

Mussala

Board Regular
Joined
Sep 28, 2022
Messages
62
Office Version
  1. 2019
Platform
  1. Windows
Hello
I want to subtract cell value I2 from last cell before TOTAL row in column E and show the difference in adjacent cell in column F for last cell before TOTAL row in column E .
every time I add new data before TOTAL row , so here is examples
a.xlsm
ABCDEFGHI
1DATEDESCRIBEDEBITCREDITBALANCEREALAMOUNT
219/06/2023INV0014,220.004,220.0024340
319/06/2023INV0025,000.009,220.00
419/06/2023INV0031,920.0011,140.00
519/06/2023INV004270.0011,410.00
619/06/2023INV0054,220.0015,630.00
719/06/2023INV0063,700.0019,330.00
819/06/2023INV0072,460.0021,790.00
919/06/2023INV0081,000.0022,790.00
1019/06/2023EXPENSES44.0022,746.00
1119/06/2023EXPENSES30.0022,716.00
1219/06/2023EXPENSES65.0022,651.00
1319/06/2023EXPENSES11.0022,640.00
14TOTAL22,790.00150.0022,640.00
s



result

a.xlsm
ABCDEFGHI
1DATEDESCRIBEDEBITCREDITBALANCEREALAMOUNT
219/06/2023INV0014,220.004,220.0024340
319/06/2023INV0025,000.009,220.00
419/06/2023INV0031,920.0011,140.00
519/06/2023INV004270.0011,410.00
619/06/2023INV0054,220.0015,630.00
719/06/2023INV0063,700.0019,330.00
819/06/2023INV0072,460.0021,790.00
919/06/2023INV0081,000.0022,790.00
1019/06/2023EXPENSES44.0022,746.00
1119/06/2023EXPENSES30.0022,716.00
1219/06/2023EXPENSES65.0022,651.00
1319/06/2023EXPENSES11.0022,640.001,700
14TOTAL22,790.00150.0022,640.00
s






another example
a.xlsm
ABCDEFGHI
1DATEDESCRIBEDEBITCREDITBALANCEREALAMOUNT
219/06/2023INV0014,220.004,220.0022500
319/06/2023INV0025,000.009,220.00
419/06/2023INV0031,920.0011,140.00
519/06/2023INV004270.0011,410.00
619/06/2023INV0054,220.0015,630.00
719/06/2023INV0063,700.0019,330.00
819/06/2023INV0072,460.0021,790.00
919/06/2023INV0081,000.0022,790.00
1019/06/2023EXPENSES44.0022,746.00
1119/06/2023EXPENSES30.0022,716.00
1219/06/2023EXPENSES65.0022,651.00
1319/06/2023EXPENSES11.0022,640.00
14TOTAL22,790.00150.0022,640.00
s



result
a.xlsm
ABCDEFGHI
1DATEDESCRIBEDEBITCREDITBALANCEREALAMOUNT
219/06/2023INV0014,220.004,220.0022500
319/06/2023INV0025,000.009,220.00
419/06/2023INV0031,920.0011,140.00
519/06/2023INV004270.0011,410.00
619/06/2023INV0054,220.0015,630.00
719/06/2023INV0063,700.0019,330.00
819/06/2023INV0072,460.0021,790.00
919/06/2023INV0081,000.0022,790.00
1019/06/2023EXPENSES44.0022,746.00
1119/06/2023EXPENSES30.0022,716.00
1219/06/2023EXPENSES65.0022,651.00
1319/06/2023EXPENSES11.0022,640.00-140
14TOTAL22,790.00150.0022,640.00
s
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
Is this what you mean?

23 06 20.xlsm
ABCDEFGHI
1DATEDESCRIBEDEBITCREDITBALANCEREALAMOUNT
219/06/2023INV00142204220 22500
319/06/2023INV00250009220 
419/06/2023INV003192011140 
519/06/2023INV00427011410 
619/06/2023INV005422015630 
719/06/2023INV006370019330 
819/06/2023INV007246021790 
919/06/2023INV008100022790 
1019/06/2023EXPENSES4422746 
1119/06/2023EXPENSES3022716 
1219/06/2023EXPENSES6522651 
1319/06/2023EXPENSES1122640-140
14TOTAL2279015022640
Row before total
Cell Formulas
RangeFormula
F2:F13F2=IF(A3="TOTAL",I$2-E2,"")
 
Upvote 0
Hi Peter ,
I want to do that automatically when write the amount in cell I2 , then show the value directly .
 
Upvote 0
I want to do that automatically
Do you want vba then? You could try this Worksheet_Change event code with a copy of your workbook.

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
  Dim rTot As Range
  
  Set rTot = Columns("A").Find(What:="TOTAL")
  If Not rTot Is Nothing Then
    Application.EnableEvents = False
    Range("F2", Range("F" & Rows.Count).End(xlUp).Offset(1)).ClearContents
    Range("F" & rTot.Row - 1).Value = Range("I2").Value - Range("E" & rTot.Row - 1).Value
    Application.EnableEvents = True
  End If
End Sub
 
Upvote 0
perfect!
just I need highlight red when show minus value and if positive value then should delete color .
thank you .
 
Upvote 0
Try

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
  Dim rTot As Range
  
  Set rTot = Columns("A").Find(What:="TOTAL")
  If Not rTot Is Nothing Then
    Application.EnableEvents = False
    Range("F2", Range("F" & Rows.Count).End(xlUp).Offset(1)).Clear
    With Range("F" & rTot.Row - 1)
      .Value = Range("I2").Value - Range("E" & rTot.Row - 1).Value
      If .Value < 0 Then .Interior.Color = vbRed
    End With
    Application.EnableEvents = True
  End If
End Sub
 
Upvote 1
Solution
You're welcome. Thanks for the follow-up. :)
 
Upvote 0

Forum statistics

Threads
1,215,491
Messages
6,125,102
Members
449,205
Latest member
ralemanygarcia

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top