If I delete row from sheet then decrease amount in other sheet

Omran Y

Board Regular
Joined
Jul 17, 2023
Messages
60
Office Version
  1. 2013
Platform
  1. Windows
Hi
in TT sheet when try deleting row then should decrease amount in column D for adjacent cells(NAME,NET AMOUNT) ignoring SALARY
into EMPLOYEES sheet base on matching NAME in column C between two sheets.
data.xlsm
ABCD
1START DATELAST DATENAMEFIRST BALANCE
201/01/202331/01/2023OMAR ALI OMAR-20,000.00
3SALARY3,000.00
4NET AMOUNT-17,000.00
5
6
7START DATELAST DATENAMEFIRST BALANCE
801/01/202331/01/2023AHMED OMAR ALI24,000.00
9SALARY12,000.00
10NET AMOUNT36,000.00
11
12
13START DATELAST DATENAMEFIRST BALANCE
1401/01/202331/01/2023ALI MAHMUD OMAR10,000.00
15SALARY2,500.00
16NET AMOUNT12,500.00
EMPLOYEES


data.xlsm
ABCD
1NAMEFIRST BALANCESALARYNET AMOUNT
211/02/2023OMAR ALI OMARAdvance payment by safe2,000.00
312/02/2023ALI MAHMUD OMARAdvance payment by bank2,500.00
413/02/2023AHMED OMAR ALIPay payment safe3,000.00
514/03/2023OMAR ALI OMARPay payment bank5,000.00
TT


Delete row from TT sheet as in lastrow
data.xlsm
ABCD
1NAMEFIRST BALANCESALARYNET AMOUNT
211/02/2023OMAR ALI OMARAdvance payment by safe2,000.00
312/02/2023ALI MAHMUD OMARAdvance payment by bank2,500.00
413/02/2023AHMED OMAR ALIPay payment safe3,000.00
514/03/2023OMAR ALI OMARPay payment bank5,000.00
TT

if the amount is minus for adjacent cells(NAME) then shoud decrease amount by add to amount for adjacent cells(NAME) and change amount for adjacent cells(NET AMOUNT) by sum amounts for for adjacent cells(NAME,SALARY) .
so see how become as highlighted by red
data.xlsm
ABCD
1START DATELAST DATENAMEFIRST BALANCE
201/01/202331/01/2023OMAR ALI OMAR-15,000.00
3SALARY3,000.00
4NET AMOUNT-12,000.00
5
6
7START DATELAST DATENAMEFIRST BALANCE
801/01/202331/01/2023AHMED OMAR ALI24,000.00
9SALARY12,000.00
10NET AMOUNT36,000.00
11
12
13START DATELAST DATENAMEFIRST BALANCE
1401/01/202331/01/2023ALI MAHMUD OMAR10,000.00
15SALARY2,500.00
16NET AMOUNT12,500.00
EMPLOYEES


another case to delete row from TT sheet
data.xlsm
ABCD
1NAMEFIRST BALANCESALARYNET AMOUNT
211/02/2023OMAR ALI OMARAdvance payment by safe2,000.00
312/02/2023ALI MAHMUD OMARAdvance payment by bank2,500.00
413/02/2023AHMED OMAR ALIPay payment safe3,000.00
TT

if the amount is positive for adjacent cells(NAME) then shoud decrease amount by subtract from amount for adjacent cells(NAME) and change amount for adjacent cells(NET AMOUNT) by sum amounts for for adjacent cells(NAME,SALARY) .
so see how become as highlighted by red
data.xlsm
ABCD
1START DATELAST DATENAMEFIRST BALANCE
201/01/202331/01/2023OMAR ALI OMAR-15,000.00
3SALARY3,000.00
4NET AMOUNT-12,000.00
5
6
7START DATELAST DATENAMEFIRST BALANCE
801/01/202331/01/2023AHMED OMAR ALI21,000.00
9SALARY12,000.00
10NET AMOUNT33,000.00
11
12
13START DATELAST DATENAMEFIRST BALANCE
1401/01/202331/01/2023ALI MAHMUD OMAR10,000.00
15SALARY2,500.00
16NET AMOUNT12,500.00
EMPLOYEES
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
First make sure that column D in both sheets is formatted as 'Number'. Next copy and paste this code into the worksheet code module. Do the following: right click the tab name for your "TT" sheet and click 'View Code'. Paste the code into the empty code window that opens up. Close the code window to return to your sheet. Delete the desired row in "TT".
VBA Code:
Dim lRow As Long, sName As String, Net As Long

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    lRow = Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
    sName = Range("B" & Target.Row)
    Net = Range("D" & Target.Row)
End Sub

Private Sub Worksheet_Change(ByVal Target As Range)
    Application.ScreenUpdating = False
    Dim LastRow As Long, fnd As Range
    LastRow = Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
    If lRow > LastRow Then
        Set fnd = Sheets("EMPLOYEES").Range("C:C").Find(sName, LookIn:=xlValues, lookat:=xlWhole)
        If Not fnd Is Nothing Then
            If fnd.Offset(, 1) < 0 Then
                fnd.Offset(, 1) = fnd.Offset(, 1) + Net
                fnd.Offset(2, 1) = fnd.Offset(2, 1) + Net
            Else
                fnd.Offset(, 1) = fnd.Offset(, 1) - Net
                fnd.Offset(2, 1) = fnd.Offset(2, 1) - Net
            End If
        End If
    End If
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
Solution
Great !
I thought my thread is not clear .:rolleyes:
many thanks buddy .:)
 
Upvote 0

Forum statistics

Threads
1,223,885
Messages
6,175,184
Members
452,615
Latest member
bogeys2birdies

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