Hello
I want matching names in column C for EMPLOYEE sheets with column B for TT sheet based on DATE (TODAY) if the column C in TT sheet contains Advance payment and the column A is DATE in TT sheet , then should subtract amount for adjacent cell for the name in EMPLOYEE sheet from amount for adjacent cell for the word Advance payment, if the column C in TT sheet contains Pay payment and the column A is DATE in TT sheet then should sum amount for adjacent cell for the name in EMPLOYEE sheet from amount for adjacent cell for the word Pay payment, and when repeat the same name in TT sheet and repeat the date today in column A then should get the mount from the last row contains date ,name when calculation by sum or subtract based on column C in TT sheet for two words(Advance payment,Pay payment).
also change adjacent cell for NET AMOUNT by sum amount for adjacent NAME and adjacent cell for SALARY in EMPLOYEES
ORIGINAL DATA for EMPLOYEES ,TT sheets
so when brings the amount from TT sheet should brings from the last row for the repeat name in column C and repeate DATE from column A as highlighted by red , as to yellow there is no repeated name .
the result in EMPLOYEES sheet should be as highlighted by red which cells should change them .
by the way I got this code by Dante's assistance , but I want adjusting or alternative
sum or subtract for the same cell based on match column between two sheets
thanks
I want matching names in column C for EMPLOYEE sheets with column B for TT sheet based on DATE (TODAY) if the column C in TT sheet contains Advance payment and the column A is DATE in TT sheet , then should subtract amount for adjacent cell for the name in EMPLOYEE sheet from amount for adjacent cell for the word Advance payment, if the column C in TT sheet contains Pay payment and the column A is DATE in TT sheet then should sum amount for adjacent cell for the name in EMPLOYEE sheet from amount for adjacent cell for the word Pay payment, and when repeat the same name in TT sheet and repeat the date today in column A then should get the mount from the last row contains date ,name when calculation by sum or subtract based on column C in TT sheet for two words(Advance payment,Pay payment).
also change adjacent cell for NET AMOUNT by sum amount for adjacent NAME and adjacent cell for SALARY in EMPLOYEES
ORIGINAL DATA for EMPLOYEES ,TT sheets
OU.xlsm | ||||||
---|---|---|---|---|---|---|
A | B | C | D | |||
1 | START DATE | LAST DATE | NAME | FIRST BALANCE | ||
2 | 01/01/2023 | 31/01/2023 | OMAR ALI OMAR | -20,000.00 | ||
3 | SALARY | 3,000.00 | ||||
4 | NET AMOUNT | -17,000.00 | ||||
5 | ||||||
6 | ||||||
7 | START DATE | LAST DATE | NAME | FIRST BALANCE | ||
8 | 01/01/2023 | 31/01/2023 | AHMED OMAR ALI | -2,000.00 | ||
9 | SALARY | 3,000.00 | ||||
10 | NET AMOUNT | 1,000.00 | ||||
11 | ||||||
12 | ||||||
13 | START DATE | LAST DATE | NAME | FIRST BALANCE | ||
14 | 01/01/2023 | 31/01/2023 | ALI MAHMUD OMAR | 1,000.00 | ||
15 | SALARY | 2,500.00 | ||||
16 | NET AMOUNT | 3,500.00 | ||||
EMPLOYEES |
OU.xlsm | ||||||
---|---|---|---|---|---|---|
A | B | C | D | |||
1 | DATE | NAME | DETAILS | AMOUNT | ||
2 | 11/02/2023 | OMAR ALI OMAR | Advance payment by safe | 2,000.00 | ||
3 | 12/02/2023 | ALI MAHMUD OMAR | Advance payment by bank | 2,500.00 | ||
4 | 13/02/2023 | AHMED OMAR ALI | Pay payment safe | 3,000.00 | ||
5 | 14/03/2023 | OMAR ALI OMAR | Pay payment bank | 5,000.00 | ||
6 | 15/03/2023 | OMAR ALI OMAR | Advance payment by safe | 3,000.00 | ||
7 | 16/03/2023 | OMAR ALI OMAR | Pay payment bank | 1,200.00 | ||
8 | 17/03/2023 | ALI MAHMUD OMAR | Advance payment by bank | 8,000.00 | ||
9 | 17/03/2023 | OMAR ALI OMAR | Pay payment bank | 2,000.00 | ||
10 | 17/03/2023 | OMAR ALI OMAR | Advance payment by safe | 3,000.00 | ||
11 | 17/03/2023 | AHMED OMAR ALI | Pay payment bank | 3,000.00 | ||
12 | 17/03/2023 | ALI MAHMUD OMAR | Pay payment bank | 3,000.00 | ||
TT |
so when brings the amount from TT sheet should brings from the last row for the repeat name in column C and repeate DATE from column A as highlighted by red , as to yellow there is no repeated name .
OU.xlsm | ||||||
---|---|---|---|---|---|---|
A | B | C | D | |||
1 | DATE | NAME | DETAILS | AMOUNT | ||
2 | 11/02/2023 | OMAR ALI OMAR | Advance payment by safe | 2,000.00 | ||
3 | 12/02/2023 | ALI MAHMUD OMAR | Advance payment by bank | 2,500.00 | ||
4 | 13/02/2023 | AHMED OMAR ALI | Pay payment safe | 3,000.00 | ||
5 | 14/03/2023 | OMAR ALI OMAR | Pay payment bank | 5,000.00 | ||
6 | 15/03/2023 | OMAR ALI OMAR | Advance payment by safe | 3,000.00 | ||
7 | 16/03/2023 | OMAR ALI OMAR | Pay payment bank | 1,200.00 | ||
8 | 17/03/2023 | ALI MAHMUD OMAR | Advance payment by bank | 8,000.00 | ||
9 | 17/03/2023 | OMAR ALI OMAR | Pay payment bank | 2,000.00 | ||
10 | 17/03/2023 | OMAR ALI OMAR | Advance payment by safe | 3,000.00 | ||
11 | 17/03/2023 | AHMED OMAR ALI | Pay payment bank | 3,000.00 | ||
12 | 17/03/2023 | ALI MAHMUD OMAR | Pay payment bank | 3,000.00 | ||
TT |
the result in EMPLOYEES sheet should be as highlighted by red which cells should change them .
OU.xlsm | ||||||
---|---|---|---|---|---|---|
A | B | C | D | |||
1 | START DATE | LAST DATE | NAME | FIRST BALANCE | ||
2 | 01/01/2023 | 31/01/2023 | OMAR ALI OMAR | -23,000.00 | ||
3 | SALARY | 3,000.00 | ||||
4 | NET AMOUNT | -20,000.00 | ||||
5 | ||||||
6 | ||||||
7 | START DATE | LAST DATE | NAME | FIRST BALANCE | ||
8 | 01/01/2023 | 31/01/2023 | AHMED OMAR ALI | 1,000.00 | ||
9 | SALARY | 3,000.00 | ||||
10 | NET AMOUNT | 4,000.00 | ||||
11 | ||||||
12 | ||||||
13 | START DATE | LAST DATE | NAME | FIRST BALANCE | ||
14 | 01/01/2023 | 31/01/2023 | ALI MAHMUD OMAR | 4,000.00 | ||
15 | SALARY | 2,500.00 | ||||
16 | NET AMOUNT | 6,500.00 | ||||
EMPLOYEES |
by the way I got this code by Dante's assistance , but I want adjusting or alternative
sum or subtract for the same cell based on match column between two sheets
VBA Code:
Sub sum_or_subtract()
Dim f As Range, c As Range
Dim det As String
Dim v As Double
Dim lr As Long
det = LCase("Advance payment")
With Sheets("TT")
lr = .Range("B" & Rows.Count).End(3).Row
For Each c In .Range("B2:B" & lr)
If WorksheetFunction.CountIf(.Range(c, .Range("B" & lr)), c.Value) = 1 Then
Set f = Sheets("EMPLOYEES").Range("C:C").Find(c.Value, , xlValues, xlWhole, , , False)
If Not f Is Nothing Then
v = c.Offset(, 2).Value * IIf(Left(LCase(c.Offset(, 1).Value), Len(det)) = det, -1, 1)
f.Offset(0, 1).Value = f.Offset(0, 1).Value + v
f.Offset(2, 1).Value = f.Offset(0, 1).Value + f.Offset(1, 1).Value
End If
End If
Next
End With
End Sub