Combine amounts of duplicate Invoice numbers with the help of a code

RAJESH1960

Banned for repeated rules violations
Joined
Mar 26, 2020
Messages
2,313
Office Version
  1. 2019
Platform
  1. Windows
Hello guys,
I have to convert this sheet compatible to run the code shared by JohnnyL. In the 2B sheet there are rows which have duplicate Invoice number due to multiple class of tax in the Rate column. I have to remove the duplicate invoice numbers in which GSTIN, Trade Name and Invoice date have also the same duplicate values. But before removing them rows which have duplicate invoice number , the amounts in Taxable value, Integrated Tax, Central tax and central tax have to be added and displayed in the one row which is not deleted. To know which rows have multiple class of tax, the rates column should display the combined values of rate of the rows deleted. Finally, all the invoice numbers should be joined with the text "-Total" after the invoice number. The code should display the result in a new sheet with the name "PORTAL", so that I don't have to edit the code connected to this sheet. Thank you in advance.
Combine amounts of duplicate Invoice Numbers.xlsm
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
that's a pivottable, except for the rate%
Combine amounts of duplicate Invoice Numbers.xlsm
ABCDEFGHIJKLM
23
24
25
26Waarden
27Trade/Legal nameGSTIN of supplierInvoice numberAInvoice DateBCDRate(%)Som van Taxable Value (₹)Som van Integrated Tax(₹)Som van Central Tax(₹)Som van State/UT Tax(₹)
28January24ABCD1234100(leeg)02/08/2021(leeg)(leeg)(leeg)2.978,40148,9200
29101(leeg)05/08/2021(leeg)(leeg)(leeg)10.857,90704,7400
30102(leeg)22/06/2021(leeg)(leeg)(leeg)38.619,022.671,7300
31103(leeg)09/12/2021(leeg)(leeg)(leeg)1.013,6350,6800
32104(leeg)09/12/2021(leeg)(leeg)(leeg)10.627,201.275,2600
33105(leeg)11/12/2021(leeg)(leeg)(leeg)18.817,941.147,9600
34107(leeg)23/06/2021(leeg)(leeg)(leeg)2.822,00338,6400
35February24ABCD1234100(leeg)15/09/2021(leeg)(leeg)(leeg)49.226,002.461,3000
36March27ABCD1235101(leeg)23/09/2021(leeg)(leeg)(leeg)26.000,000,0012801280
37April29ABCD1236101(leeg)23/08/2021(leeg)(leeg)(leeg)33.721,430,00843,04843,04
38May29ABCD1237101(leeg)12/08/2021(leeg)(leeg)(leeg)17.898,00894,9000
39September09ABCD1241101(leeg)08/04/2021(leeg)(leeg)(leeg)1.588,470,00155,71155,71
40October29ABCD1242101(leeg)29/06/2021(leeg)(leeg)(leeg)2.585,00129,2500
41November27ABCD1243101(leeg)22/04/2021(leeg)(leeg)(leeg)26.290,003.673,2000
42December06ABCD1244101(leeg)12/04/2021(leeg)(leeg)(leeg)6.526,460,00726,38726,38
43Eindtotaal249.571,4513.496,583005,133005,13
44
45
Expected Result
 
Upvote 0
that's a pivottable, except for the rate%
Combine amounts of duplicate Invoice Numbers.xlsm
ABCDEFGHIJKLM
23
24
25
26Waarden
27Trade/Legal nameGSTIN of supplierInvoice numberAInvoice DateBCDRate(%)Som van Taxable Value (₹)Som van Integrated Tax(₹)Som van Central Tax(₹)Som van State/UT Tax(₹)
28January24ABCD1234100(leeg)02/08/2021(leeg)(leeg)(leeg)2.978,40148,9200
29101(leeg)05/08/2021(leeg)(leeg)(leeg)10.857,90704,7400
30102(leeg)22/06/2021(leeg)(leeg)(leeg)38.619,022.671,7300
31103(leeg)09/12/2021(leeg)(leeg)(leeg)1.013,6350,6800
32104(leeg)09/12/2021(leeg)(leeg)(leeg)10.627,201.275,2600
33105(leeg)11/12/2021(leeg)(leeg)(leeg)18.817,941.147,9600
34107(leeg)23/06/2021(leeg)(leeg)(leeg)2.822,00338,6400
35February24ABCD1234100(leeg)15/09/2021(leeg)(leeg)(leeg)49.226,002.461,3000
36March27ABCD1235101(leeg)23/09/2021(leeg)(leeg)(leeg)26.000,000,0012801280
37April29ABCD1236101(leeg)23/08/2021(leeg)(leeg)(leeg)33.721,430,00843,04843,04
38May29ABCD1237101(leeg)12/08/2021(leeg)(leeg)(leeg)17.898,00894,9000
39September09ABCD1241101(leeg)08/04/2021(leeg)(leeg)(leeg)1.588,470,00155,71155,71
40October29ABCD1242101(leeg)29/06/2021(leeg)(leeg)(leeg)2.585,00129,2500
41November27ABCD1243101(leeg)22/04/2021(leeg)(leeg)(leeg)26.290,003.673,2000
42December06ABCD1244101(leeg)12/04/2021(leeg)(leeg)(leeg)6.526,460,00726,38726,38
43Eindtotaal249.571,4513.496,583005,133005,13
44
45
Expected Result
BSALV/ Thanks for the response. I am trying to get it with the help of a code/ It is just a part of the code which will be added to the already existing code.. There is a lot of editing and manual work involved in using pivot table, like filling the blank ,etc. Getting the values of one invoice number with different rates in one row is also not possible. Also, the sheet is a merged one with headings in different rows. I have to get the result without changing the original data sheet.
 
Last edited:
Upvote 0
VBA solution:
VBA Code:
Option Explicit
Sub add()
Dim lr&, k&, j&, id As String, item As String, cell As Range, s, key, arr(), ws As Worksheet
Dim dic As Object
Set dic = CreateObject("scripting.dictionary")
Application.ScreenUpdating = False
Application.DisplayAlerts = False
For Each ws In Sheets
    If ws.Name = "PORTAL" Then ws.Delete ' delete previous version of sheet PORTAL
Next
Application.DisplayAlerts = True
Worksheets("2B").Activate
lr = Cells(Rows.Count, "A").End(xlUp).Row
    For Each cell In Range("A7:A" & lr)
        id = cell & "|" & cell.Offset(0, 1) & "|" & cell.Offset(0, 2) ' column A&B&C combination
        item = cell.Offset(0, 4) & "|" & cell.Offset(0, 8) & "|" & cell.Offset(0, 9) & "|" & cell.Offset(0, 10) _
                & "|" & cell.Offset(0, 11) & "|" & cell.Offset(0, 12) & "|" & cell.Offset(0, 13)
            If Not dic.exists(id) Then
                dic.add id, item
            Else
                s = Split(dic(id), "|")
                dic(id) = s(0) & "|" & s(1) & "+" & cell.Offset(0, 8) & "|" & _
                s(2) + cell.Offset(0, 9) & "|" & _
                s(3) + cell.Offset(0, 10) & "|" & _
                s(4) + cell.Offset(0, 11) & "|" & _
                s(5) + cell.Offset(0, 12) & "|" & _
                s(6) + cell.Offset(0, 13)
            End If
    Next
Sheets.add after:=ActiveSheet
ActiveSheet.Name = "PORTAL"
Worksheets("2B").Range("A1:V6").Copy Range("A1")
ReDim arr(1 To dic.Count, 1 To 22)
    For Each key In dic.keys
        k = k + 1
        For j = 1 To 22
            Select Case j
                Case 1, 2, 3
                    arr(k, j) = Split(key, "|")(j - 1) & IIf(j = 3, "-Total", "")
                Case 5
                    arr(k, j) = Split(dic(key), "|")(0)
                Case 9, 10, 11, 12, 13
                    arr(k, j) = Split(dic(key), "|")(j - 8)
            End Select
        Next
    Next
With Range("A7").Resize(dic.Count, 22)
    .Value = arr
    .EntireColumn.AutoFit
    .Columns(9).HorizontalAlignment = xlCenter
End With
Range("J7:M" & dic.Count+6).NumberFormat = "#,##0.00"
Application.ScreenUpdating = True
End Sub
 
Upvote 0
Solution
Wow!! Unbelievable. It's magic. The things you can do with VBA coding is just incredible. If done right in the first time, one hour of manual work done in just 1 second. When done manually, there may be mistakes and I have to do it again from the beginning and that would take more than an hour. But this is done just so perfect with this code.
The date has always been a problem in most of my projects, but it is ok in this case since I have to match the amounts only.
Thank you very much Bebo02 for the solution and your valuable time to share this code.
 
Upvote 0
Bebo02. I have just posted a New post query which is connected to the above post. As you have understood it I hope you will be able to solve it easily.
 
Upvote 0
just a small improvement/adjustment to speed up
* read that table to an array (with ".value2" because it contains dates)
* instead of just 1 element in the items, do them all, in an array. So you don't have to split later.
That code is a little bit more complicated, but if you have to do a lot of rows, it'll need a fraction of the time to execute.
 
Upvote 0
Bebo02. I have just posted a New post query which is connected to the above post. As you have understood it I hope you will be able to solve it easily.
This is regarding the above message. There is no problem at all. Sorry. It was my mistake to have tried in a different data with duplicates.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,177
Members
453,021
Latest member
Justyna P

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