How merging by sum DEBIT,CREDIT columns for each name

Abdo

Board Regular
Joined
May 16, 2022
Messages
228
Office Version
  1. 2019
  2. 2010
Platform
  1. Windows
Hi experts,
I hope finding macro to deal with client no to merge amounts in DEBIT , CREDIT but the merging will be for duplicates CLIENT NO within two dates when add data for every time .
so the report will be in columns I:N
in columns I,J will brings from column A and column K will brings from column C and columns LM will merge from column E ,F based on duplicates client no in column C within dates in column A .
the column N will subtract column L from column F and insert TOTAL row to sum column L,M .
example:
المصنف1
ABCDEFGHIJKLMNO
1DATEINVOICE NOCLIENT NODESCRIBEDEBITCREDITBALANCE
201/01/2022-ABDEND1OPENNING20,000.000.0020,000.00
304/01/2022PA-B3ABDEND1PA20,000.000.0040,000.00
405/01/2022SA-B35ABDEND1SA0.001,000.0039,000.00
DEB




result

المصنف1
ABCDEFGHIJKLMN
1DATEINVOICE NOCLIENT NODESCRIBEDEBITCREDITBALANCEFROM DATETO DATECLIENT NODEBITCREDITBALANCE
201/01/2022-ABDEND1OPENNING20,000.000.0020,000.0001/01/202205/01/2022ABDEND140,000.001,000.0039,000.00
304/01/2022PA-B3ABDEND1PA20,000.000.0040,000.00TOTAL40,000.001,000.0039,000.00
405/01/2022SA-B35ABDEND1SA0.001,000.0039,000.00
DEB
Cell Formulas
RangeFormula
N2:N3N2=L2-M2
L3:M3L3=SUM(L2)


example:
المصنف1
ABCDEFGHIJKLMN
1DATEINVOICE NOCLIENT NODESCRIBEDEBITCREDITBALANCEFROM DATETO DATECLIENT NODEBITCREDITBALANCE
201/01/2022-ABDEND1OPENNING20,000.000.0020,000.0001/01/202205/01/2022ABDEND140,000.001,000.0039,000.00
304/01/2022PA-B3ABDEND1PA20,000.000.0040,000.00TOTAL40,000.001,000.0039,000.00
405/01/2022SA-B35ABDEND1SA0.001,000.0039,000.00
506/01/2022-ABDEND10OPENNING10,000.000.0010,000.00
606/01/2022PA-B4ABDEND10PA2,000.008,000.00
707/01/2022SA-B36ABDEND10SA0.00500.007,500.00
DEB
Cell Formulas
RangeFormula
N2:N3N2=L2-M2
L3:M3L3=SUM(L2:L2)



result
المصنف1
ABCDEFGHIJKLMN
1DATEINVOICE NOCLIENT NODESCRIBEDEBITCREDITBALANCEFROM DATETO DATECLIENT NODEBITCREDITBALANCE
201/01/2022-ABDEND1OPENNING20,000.000.0020,000.0001/01/202205/01/2022ABDEND140,000.001,000.0039,000.00
304/01/2022PA-B3ABDEND1PA20,000.000.0040,000.0006/01/202207/01/2022ABDEND1010,000.002,500.007,500.00
405/01/2022SA-B35ABDEND1SA0.001,000.0039,000.00TOTAL50,000.003,500.0046,500.00
506/01/2022-ABDEND10OPENNING10,000.000.0010,000.00
606/01/2022PA-B4ABDEND10PA2,000.008,000.00
707/01/2022SA-B36ABDEND10SA0.00500.007,500.00
DEB
Cell Formulas
RangeFormula
N2:N4N2=L2-M2
L4:M4L4=SUM(L2:L3)



another example and important
المصنف1
ABCDEFGHIJKLMN
1DATEINVOICE NOCLIENT NODESCRIBEDEBITCREDITBALANCEFROM DATETO DATECLIENT NODEBITCREDITBALANCE
201/01/2022-ABDEND1OPENNING20,000.000.0020,000.0001/01/202205/01/2022ABDEND140,000.001,000.0039,000.00
304/01/2022PA-B3ABDEND1PA20,000.000.0040,000.0006/01/202207/01/2022ABDEND1010,000.002,500.007,500.00
405/01/2022SA-B35ABDEND1SA0.001,000.0039,000.00TOTAL50,000.003,500.0046,500.00
506/01/2022-ABDEND10OPENNING10,000.000.0010,000.00
606/01/2022PA-B4ABDEND10PA2,000.008,000.00
707/01/2022SA-B36ABDEND10SA0.00500.007,500.00
809/01/2022PA-B5ABDEND1PA1,200.000.001,200.00
910/01/2022PA-B6ABDEND1SA1,000.002,200.00
1011/01/2022SA-B38ABDEND1SA0.002,000.00200.00
DEB
Cell Formulas
RangeFormula
N2:N4N2=L2-M2
L4:M4L4=SUM(L2:L3)


result
المصنف1
ABCDEFGHIJKLMN
1DATEINVOICE NOCLIENT NODESCRIBEDEBITCREDITBALANCEFROM DATETO DATECLIENT NODEBITCREDITBALANCE
201/01/2022-ABDEND1OPENNING20,000.000.0020,000.0001/01/202205/01/2022ABDEND140,000.001,000.0039,000.00
304/01/2022PA-B3ABDEND1PA20,000.000.0040,000.0006/01/202207/01/2022ABDEND1010,000.002,500.007,500.00
405/01/2022SA-B35ABDEND1SA0.001,000.0039,000.0009/01/202211/01/2022ABDEND12,200.002,000.00200.00
506/01/2022-ABDEND10OPENNING10,000.000.0010,000.00TOTAL52,200.005,500.0046,700.00
606/01/2022PA-B4ABDEND10PA2,000.008,000.00
707/01/2022SA-B36ABDEND10SA0.00500.007,500.00
809/01/2022PA-B5ABDEND1PA1,200.000.001,200.00
910/01/2022PA-B6ABDEND1SA1,000.002,200.00
1011/01/2022SA-B38ABDEND1SA0.002,000.00200.00
DEB
Cell Formulas
RangeFormula
N5,N2:N3N2=L2-M2
L5:M5L5=SUM(L2:L4)

as you see there is duplicates client no then should not merge for all of duplicates name, just merge within two dates alone for new process.
the project depends on add new data for every time so when add previous data don't repeat again.

I hope to get chance who can write code for me.
thanks
 
You need to tell us clear logic to separate the data.
actually I haven't ,but I will think something maybe help you and comeback later.
 
Upvote 0

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Well when run the macro then will write DONE word in column H for last row like this
DD‬.xlsx
ABCDEFGHIJKLMN
1DateINVOICE NOCLIENT NODESCRIBEDEBITCREDITBALANCEFROM DATETO DATECLIENT NODEBITCREDITBALANCE
201/01/2022-ABDEND1OPENNING20,000.000.0020,000.0001/01/202205/01/2022ABDEND140,000.001,000.0039,000.00
304/01/2022PA-B3ABDEND1PA20,000.000.0040,000.00TOTAL40,000.000.000.00
405/01/2022SA-B35ABDEND1SA0.001,000.0039,000.00DONE
DEB
Cell Formulas
RangeFormula
L3L3=SUM(L$2:L2)
M3:N3M3=SUM(M$2:M3)


and when enter new data will start after DONE word like this.
DD.xlsx
ABCDEFGHIJKLMN
1DateINVOICE NOCLIENT NODESCRIBEDEBITCREDITBALANCEFROM DATETO DATECLIENT NODEBITCREDITBALANCE
201/01/2022-ABDEND1OPENNING20,000.000.0020,000.0001/01/202205/01/2022ABDEND140,000.001,000.0039,000.00
304/01/2022PA-B3ABDEND1PA20,000.000.0040,000.0005/01/202207/01/2022ABDEND12,000.00-2,000.00
405/01/2022SA-B35ABDEND1SA0.001,000.0039,000.00DONETOTAL40,000.003,000.0037,000.00
505/01/2022SA-B36ABDEND1SA0.001,000.0038,000.00
607/01/2022SA-B37ABDEND1SA0.001,000.0037,000.00DONE
DEB
Cell Formulas
RangeFormula
L4:N4L4=SUM(L$2:L3)

I hope this is is logical.
 
Upvote 0
Code:
Sub test()
    Dim a, i&, ii&, iii&, n&, temp
    With Sheets("deb")
        a = .[a1].CurrentRegion.Resize(, 8).Value2
        ReDim b(1 To UBound(a, 1), 1 To 6)
        .Columns("i:n").Clear
        For i = 2 To UBound(a, 1)
            If (temp <> a(i, 3)) + (a(i, 8) = "DONE") Then
                temp = a(i, 3): n = n + 1: ii = 0
                b(n, 1) = a(i, 1): b(n, 2) = a(i, 1): b(n, 3) = a(i, 3)
                Do While temp = a(i + ii, 3)
                    If b(n, 1) > a(i + ii, 1) Then b(n, 1) = a(i + ii, 1)
                    If b(n, 2) < a(i + ii, 1) Then b(n, 2) = a(i + ii, 1)
                    For iii = 1 To 2
                        b(n, iii + 3) = b(n, iii + 3) + a(i + ii, iii + 4)
                    Next
                    b(n, 6) = b(n, 4) - b(n, 5)
                    ii = ii + 1
                    If a(i + ii - 1, 8) = "DONE" Then temp = "": Exit Do
                    If (i + ii > UBound(a, 1)) Then Exit Do
                Loop
                i = i + ii - 1
            End If
        Next
        .Range("g" & Rows.Count).End(xlUp)(1, 2) = "DONE"
        .[a1].Copy .[i1:n1]
        .[i1:n1] = [{"FROM DATE","TO DATE","CLIENT NO","DEBIT","CREDIT","BALANCE"}]
        .[i2].Resize(n, 6) = b
        With [i1].CurrentRegion.Offset(1)
            .HorizontalAlignment = xlCenter
            .Columns("a:b").NumberFormatLocal = "dd/mm/yyyy"
            .Columns("d:f").NumberFormatLocal = "#,#.00"
            With .Rows(.Rows.Count).Cells(1)
                .Value = "TOTAL"
                .Font.Bold = True
                .Interior.Color = vbYellow
                .Range("d1:f1").FormulaR1C1 = "=sum(r2c:r[-1]c)"
            End With
        End With
        [i1].CurrentRegion.Borders.Weight = 2
    End With
End Sub
 
Upvote 0
there is problem about formatting for TOTAL row .I notice from first data will create borders under TOTAL row !
no need make borders start from column H , should be from column I.

DEB.xlsm
ABCDEFGHIJKLMN
1DateINVOICE NOCLIENT NODESCRIBEDEBITCREDITBALANCEFROM DATETO DATECLIENT NODEBITCREDITBALANCE
201/01/2022-ABDEND1OPENNING5,555.00.0020,000.0001/01/202205/01/2022ABDEND125,555.001,000.0024,555.00
304/01/2022PA-B3ABDEND1PA20,000.00.0040,000.00TOTAL25,555.001,000.0024,555.00
405/01/2022SA-B35ABDEND1SA.001,000.0039,000.00DONE
DEB
Cell Formulas
RangeFormula
L3:N3L3=SUM(L$2:L2)



when enter new data
DEB.xlsm
ABCDEFGHIJKLMN
1DateINVOICE NOCLIENT NODESCRIBEDEBITCREDITBALANCEFROM DATETO DATECLIENT NODEBITCREDITBALANCE
201/01/2022-ABDEND1OPENNING5,555.00.0020,000.0001/01/202205/01/2022ABDEND125,555.001,000.0024,555.00
304/01/2022PA-B3ABDEND1PA20,000.00.0040,000.00TOTAL25,555.001,000.0024,555.00
405/01/2022SA-B35ABDEND1SA.001,000.0039,000.00DONE
505/01/2022SA-B36ABDEND1SA2,000.0037,000.00
606/01/2022PA-B4ABDEND1PA2,000.0039,000.00
707/01/2022PA-B5ABDEND1PA2,000.0041,000.00
DEB
Cell Formulas
RangeFormula
L3:N3L3=SUM(L$2:L2)


then will move TOTAL row to range A:G and change date formatting in column I!

DEB.xlsm
ABCDEFGHIJKLMN
1DateINVOICE NOCLIENT NODESCRIBEDEBITCREDITBALANCEFROM DATETO DATECLIENT NODEBITCREDITBALANCE
201/01/2022-ABDEND1OPENNING5,555.00.0020,000.004456244566ABDEND125555100024555
304/01/2022PA-B3ABDEND1PA20,000.00.0040,000.004456644568ABDEND1400020002000
405/01/2022SA-B35ABDEND1SA.001,000.0039,000.00DONE
505/01/2022SA-B36ABDEND1SA2,000.0037,000.00
606/01/2022PA-B4ABDEND1PA2,000.0039,000.00
707/01/2022PA-B5ABDEND1PA2,000.0041,000.00DONE
8TOTAL.0029,555.003,000.00
DEB
Cell Formulas
RangeFormula
D8:F8D8=SUM(D$2:D7)
 
Upvote 0
Rich (BB code):
Sub test()
    Dim a, i&, ii&, iii&, n&, temp
    With Sheets("deb")
        .Columns("i:n").Clear
        a = .[a1].CurrentRegion.Resize(, 8).Value2
        ReDim b(1 To UBound(a, 1), 1 To 6)
        For i = 2 To UBound(a, 1)
            If (temp <> a(i, 3)) + (a(i, 8) = "DONE") Then
                temp = a(i, 3): n = n + 1: ii = 0
                b(n, 1) = a(i, 1): b(n, 2) = a(i, 1): b(n, 3) = a(i, 3)
                Do While temp = a(i + ii, 3)
                    If b(n, 1) > a(i + ii, 1) Then b(n, 1) = a(i + ii, 1)
                    If b(n, 2) < a(i + ii, 1) Then b(n, 2) = a(i + ii, 1)
                    For iii = 1 To 2
                        b(n, iii + 3) = b(n, iii + 3) + a(i + ii, iii + 4)
                    Next
                    b(n, 6) = b(n, 4) - b(n, 5)
                    ii = ii + 1
                    If a(i + ii - 1, 8) = "DONE" Then temp = "": Exit Do
                    If (i + ii > UBound(a, 1)) Then Exit Do
                Loop
                i = i + ii - 1
            End If
        Next
        .Range("g" & Rows.Count).End(xlUp)(1, 2) = "DONE"
        .[a1].Copy .[i1:n1]
        .[i1:n1] = [{"FROM DATE","TO DATE","CLIENT NO","DEBIT","CREDIT","BALANCE"}]
        .[i2].Resize(n, 6) = b
        With [i1].Resize(n + 2, UBound(b, 2))
            .HorizontalAlignment = xlCenter
            .Columns("a:b").NumberFormatLocal = "dd/mm/yyyy"
            .Columns("d:f").NumberFormatLocal = "#,#.00"
            With .Rows(.Rows.Count).Cells(1)
                .Value = "TOTAL"
                .Font.Bold = True
                .Interior.Color = vbYellow
                .Range("d1:f1").FormulaR1C1 = "=sum(r2c:r[-1]c)"
            End With
            .Borders.Weight = 2
        End With
    End With
End Sub
 
Upvote 0
Awesome!
last thing, can you add condition, please? when there is zero value into last cell BALANCE column G for adjacent cell contains DONE word in column H then should not show in range I:N (Check rows 7:9) like this
DEB.xlsm
ABCDEFGHIJKLMN
1DateINVOICE NOCLIENT NODESCRIBEDEBITCREDITBALANCEFROM DATETO DATECLIENT NODEBITCREDITBALANCE
201/01/2022-ABDEND1OPENNING20,000.000.0020,000.0001/01/202205/01/2022ABDEND140,000.001,000.0039,000.00
304/01/2022PA-B3ABDEND1PA20,000.000.0040,000.0005/01/202207/01/2022ABDEND12,000.00-2,000.00
405/01/2022SA-B35ABDEND1SA0.001,000.0039,000.00DONETOTAL40,000.003,000.0037,000.00
505/01/2022SA-B36ABDEND1SA0.001,000.0038,000.00
607/01/2022SA-B37ABDEND1ABDEND20.001,000.0037,000.00DONE
708/01/2022PA-B4ABDEND2PA3,000.003,000.00
809/01/2022PA-B5ABDEND2PA3,000.006,000.00
910/01/2022SA-B37ABDEND2SA6,000.000.00DONE
DEB
Cell Formulas
RangeFormula
L4:N4L4=SUM(L$2:L3)
 
Upvote 0
Really a poor data management...

What if the block of data contains multiple CLIENT NO up to DONE?

And when you ask question, ask everything in the initial post, otherwise it need to be re-built from scratch.
So, ask when you know everything you ask.
 
Upvote 0
What if the block of data contains multiple CLIENT NO up to DONE?
not really understand it , sorry !
if you mean there are many client no contains zero in last row should ignore when start amount until last row contains zero for adjacant DONE word for new entering data.
I suppose the code will deal for new entering data after DONE word for previous data so should search for after DONE word for previous data until DONE word for new entering data and when zero in last row for new entering data then will ignore whole range for new entering data.
And when you ask question, ask everything in the initial post, otherwise it need to be re-built from scratch.
So, ask when you know everything you ask.
understood.
 
Upvote 0
What is the result for
DateINVOICE NOCLIENT NODESCRIBEDEBITCREDITBALANCE
1/1/2022-ABDEND1OPENNING20000020000
4/1/2022PA-B3ABDEND1PA20000040000
5/1/2022SA-B35ABDEND1SA0100039000
5/1/2022SA-B36ABDEND1SA0100038000
7/1/2022SA-B37ABDEND1ABDEND20100037000
8/1/2022PA-B4ABDEND2PA30003000
9/1/2022PA-B5ABDEND2PA30006000
10/1/2022SA-B37ABDEND2SA60000DONE
 
Upvote 0
OK when I entering data for specific name will not be different others names in the same entering data.
I will enter one name for each process alone.
 
Upvote 0

Forum statistics

Threads
1,224,621
Messages
6,179,941
Members
452,949
Latest member
beartooth91

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