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
 
As I said, it is you to decide how you want to maintain/manage the data, not me.
Ask when you ready.
 
Upvote 0

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
I try to explain this idea .
so as marked client and balance I expect to say what happens about balances there is no zero , right?
1.PNG

you write to to client no
ABDEND1,ABDEND2 . this is not in my case
see the case
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/2022ABDEND1.002,000.00-2,000.00
405/01/2022SA-B35ABDEND1SA0.001,000.0039,000.00DONE11/01/202212/01/2022ABDEND24,000.00.004,000.00
505/01/2022SA-B36ABDEND1SA0.001,000.0038,000.00TOTAL44,000.003,000.0041,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-B38ABDEND2SA6,000.000.00DONE
1011/01/2022PA-B6ABDEND2PA2,000.002,000.00
1112/01/2022PA-B6ABDEND2PA2,000.004,000.00DONE
1212/01/2022PA-B7ABDEND3PA2,000.002,000.00
1313/01/2022SA-B38ABDEND3SA2,000.000.00DONE
DEB
Cell Formulas
RangeFormula
L5:N5L5=SUM(L$2:L4)


as you see every DONE word will be for just one client no , will not be more than name in one process
and any process contains zero will ignore it.
anyway if you still this is not clear for you I will mark solved for last code provide me .
 
Upvote 0
Code:
Sub test()
    Dim a, x, i&, ii&, iii&, n&
    With Sheets("deb")
        .[i:n].Clear
        With .[a1].CurrentRegion.Resize(, 8)
            x = Filter(.Parent.Evaluate(Replace("transpose(if((row(#)=1)+(#=""DONE""),row(#)))", "#", .Columns(8).Address)), False, 0)
            If UBound(x) < 1 Then Exit Sub
            a = .Value2
        End With
        ReDim b(1 To UBound(x) + 1, 1 To 6)
        For i = 0 To UBound(x) - 1
            If a(x(i + 1), 7) <> 0 Then
                n = n + 1
                b(n, 1) = a(x(i) + 1, 1): b(n, 2) = a(x(i) + 1, 1): b(n, 3) = a(x(i) + 1, 3)
                For ii = x(i) + 1 To x(i + 1)
                    If b(n, 1) > a(ii, 1) Then b(n, 1) = a(ii, 1)
                    If b(n, 2) < a(ii, 1) Then b(n, 1) = a(ii, 1)
                    For iii = 4 To 5
                        b(n, iii) = b(n, iii) + a(ii, iii + 1)
                    Next
                    b(n, 6) = b(n, 4) - b(n, 5)
                Next
            End If
        Next
        .[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 = "#,0.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
 
Last edited:
Upvote 0
Solution
application defined error or object defined error
VBA Code:
 .[i2].Resize(n, 6) = b
DEB.xlsm
ABCDEFGHIJKLMN
1DateINVOICE NOCLIENT NODESCRIBEDEBITCREDITBALANCEFROM DATETO DATECLIENT NODEBITCREDITBALANCE
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
5
DEB
 
Upvote 0
Code in #23 has been edited and if there is no "DONE" in col.H, it will do nothing, so place "DONE" at the end of Col.H.
 
Upvote 0
just question , so the code can't do that itself by add DONE word as you did in previous code if add zero condition?
 
Upvote 0
Why do you need it to do by the code?

DONE is only used for the sign of break point of each data and you decide it for yourself without any rule, so the code will not be able to determine if placing DONE at the end is correct or not.
 
Upvote 0
DONE is only used for the sign of break point of each data and you decide it for yourself without any rule, so the code will not be able to determine if placing DONE at the end is correct or not.
ok is clear .
thank you so much for everything. :)
 
Upvote 0

Forum statistics

Threads
1,224,621
Messages
6,179,937
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