extraction invoices detail for TOTAL row for each sheet individual

KalilMe

Active Member
Joined
Mar 5, 2021
Messages
354
Office Version
  1. 2016
Platform
  1. Windows
Hi
I would extract invoices details for each sheet based on TOTAL row.
so should extract columns B:D ,J for TOTAL row for each sheet individual and populate data from row2 in A:D based on sales sheet ,F:I based on buying sheet and insert TOTAL row to sum amounts in columns D,I in extraction sheet.
and will increase data in SALES,BUYING sheet. if the vba is possible then will should clear data in EXTRACTION sheet and replace data with data have already copied .
EX.xlsm
ABCDEFGHIJ
1ITEMDATENAMEINVOICEGOODSTYPEPRQTYUNITTOTAL
2125/05/2023CR-1000FRVG-1000ATRAM1GR55.0022.001,210.00
3225/05/2023CR-1000FRVG-1000ATRAM2PO14.0033.00462.00
4325/05/2023CR-1000FRVG-1000ATRAM1SO10.0044.00440.00
5TOTAL25/05/2023CR-1000FRVG-10002,112.00
6125/05/2023CR-1001FRVG-1001ATRAM1GR10.0022.00220.00
7225/05/2023CR-1001FRVG-1001ATRAM2PO10.0033.00330.00
8TOTAL25/05/2023CR-1001FRVG-1001550.00
SALES




EX.xlsm
ABCDEFGHIJ
1ITEMDATENAMEINVOICEGOODSTYPEPRQTYUNITTOTAL
2125/05/2023CR-1000STVG-1000ATRAM1MTR5.0025.00125.00
3225/05/2023CR-1000STVG-1000ATRAM2PO4.0035.00140.00
4325/05/2023CR-1000STVG-1000ATRAM1SO2.0045.0090.00
5TOTAL25/05/2023CR-1000STVG-1000355.00
6125/05/2023CR-1001STVG-1001ATRAM1GR2.0023.0046.00
7225/05/2023CR-1001STVG-1001ATRAM2PO2.0035.0070.00
8TOTAL25/05/2023CR-1001STVG-1001116.00
BUYING



EX.xlsm
ABCDEFGHI
1DATENAMESALES INVOICESTOTALDATENAMESALES INVOICESTOTAL
2
3
4
EXTRACTION



what I want it
EX.xlsm
ABCDEFGHI
1DATENAMESALES INVOICESTOTALDATENAMESALES INVOICESTOTAL
225/05/2023CR-1000FRVG-10002,112.0025/05/2023CR-1000STVG-1000355.00
325/05/2023CR-1001FRVG-1001550.0025/05/2023CR-1001STVG-1001116.00
4TOTAL2,662.00TOTAL471.00
EXTRACTION

thanks in advance
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
Power Query Solution. Once Close and Loaded to Excel, you can split the table as needed.

Power Query:
let
    Source1 = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    Source2=Excel.CurrentWorkbook(){[Name="Table2"]}[Content],
    Append =Table.Combine({Source1, Source2}),
    TotalRows=Table.SelectRows(Append, each ([ITEM] = "TOTAL")),
    #"Removed Other Columns" = Table.SelectColumns(TotalRows,{"DATE", "NAME", "INVOICE", "TOTAL"}),
    #"Changed Type" = Table.TransformColumnTypes(#"Removed Other Columns",{{"DATE", type date}, {"NAME", type text}, {"INVOICE", type text}, {"TOTAL", Currency.Type}})
in
    #"Changed Type"

DATENAMEINVOICETOTAL
5/25/2023CR-1000FRVG-10002112
5/25/2023CR-1001FRVG-1001550
5/25/2023CR-1000STVG-1000355
5/25/2023CR-1001STVG-1001116
 
Upvote 0
I don't post combining two sheets in one range as you did it!
and where is TOTAL row?
 
Upvote 0
As I indicated, you may split these in Native Excel and add the total row. Those are basic excel functions that I did not feel you needed help. Copy and Paste and then Sum.
 
Upvote 0
So in this case PQ is useless!
I want to do it automatically.
 
Upvote 0
工作簿2
ABCDEFGHI
1DATENAMESALES INVOICESTOTALDATENAMESALES INVOICESTOTAL
25/25/23CR-1000FRVG-100021125/25/23CR-1000STVG-1000355
35/25/23CR-1001FRVG-10015505/25/23CR-1001STVG-1001116
4TOTAL2662TOTAL471
EXTRACTION
Cell Formulas
RangeFormula
D4,I4D4=SUM(D2:D3)


Please give below code for a shot, right click extraction sheet -> view code -> paste below code and run the code (f5)

VBA Code:
Option Compare Text
Option Explicit
Sub test()
Dim ws As Worksheet
Set ws = Sheets("EXTRACTION")
Dim a As Variant
'Dim dict As New Dictionary ' For mac
Dim dict As object
Set dict = New Scripting.Dictionary
Dim i%, k%, lrow%
dict.CompareMode = vbTextCompare
Dim sht As Worksheet
ReDim b(1 To 5000, 1 To 5)

ws.[a2:i10000].ClearContents ' clear all text from a2 to i100000
ws.[a2:a10000].Interior.Color = xlNone ' clear total color range a2
ws.[f2:f10000].Interior.Color = xlNone 'clear total color range f2

For Each sht In Sheets(Array("SALES", "BUYING")) 'loop through sales and buying sheets
        a = sht.Range("a2:j" & sht.Cells(Rows.Count, "A").End(xlUp).Row).Value 'store into array
    For i = 1 To UBound(a, 1) 'loop through array to find existing dict
            If Not dict.Exists(a(i, 3)) Then
            k = k + 1
            dict.Add a(i, 3), k
            b(k, 1) = a(i, 2)
             b(k, 2) = a(i, 3)
             b(k, 3) = a(i, 4)
             b(k, 4) = a(i, 10)
            ElseIf a(i, 1) <> "TOTAL" Then
                b(dict(a(i, 3)), 4) = b(dict(a(i, 3)), 4) + a(i, 10)
            End If
    Next
   
    If sht.Name = "SALES" Then
          ws.[a2].Resize(UBound(b, 1), UBound(b, 2)).Value = b
          lrow = ws.Cells(Rows.Count, "A").End(xlUp).Row
          ws.Cells(lrow + 1, "A").Value = "TOTAL"
          ws.Cells(lrow + 1, "A").Interior.Color = RGB(113, 129, 186)
          ws.Cells(lrow + 1, "d").Formula = "=sum(d2:d" & lrow & ")"
    ElseIf sht.Name = "BUYING" Then
         ws.[f2].Resize(UBound(b, 1), UBound(b, 2)).Value = b
         lrow = ws.Cells(Rows.Count, "f").End(xlUp).Row
         ws.Cells(lrow + 1, "f").Value = "TOTAL"
         ws.Cells(lrow + 1, "f").Interior.Color = RGB(113, 129, 186)
          ws.Cells(lrow + 1, "i").Formula = "=sum(I2:i" & lrow & ")"
    End If

dict.RemoveAll
ReDim b(1 To 5000, 1 To 5)
k = 0
Next


End Sub
 
Last edited:
Upvote 1
Solution

Forum statistics

Threads
1,223,164
Messages
6,170,444
Members
452,326
Latest member
johnshaji

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