Combine Tables (without Total Row) into Master Tables (With Total Sum Row) based on specific sheet Like 1,2,3 to 24

Kalim Shaikh

New Member
Joined
Jun 13, 2023
Messages
24
Office Version
  1. 2021
Platform
  1. Windows
  2. Mobile
  3. Web
I have 27 sheets in a workbook they contain sheets Names 'Summary","Checking","Recheck" and "1.2.3 to 24" in Sheets "1 to 24" Contains tables with header row range ("A12:L") and last row contains total row.
Invoice NoDateMonthParticularsNatureInvoice IssueCredit NoteClaim/ Bonus1% GSTSale ReturnCheque/Online ReceivedBalance
CR-
00022515Jul-23Issued Invoice.000225 AmountDR
305,254.00
305,254.00
-
TotalRowTotal Amount305,254.00-----305,254.00

I want Tables in Sheets "1 to 24" (without Total Row) will be combined in a new Table "Final" in Range ("A12:M) Sheet Name "Recheck" (Include xlTotalsCalculationSum Row) (If possible to add a new column named "Reference". That include table name or sheet Name for reference). Leave the column "Balance" blank so that the formula can be applied.

Distribution Account Ledgers.xlsm
ABCDEFGHIJKLM
1
2
3
4
5
6
7
8
9
10"Final" Table
11Table Name" Final"
12Invoice NoDateMonthParticularsNatureInvoice IssueCredit NoteClaim/ Bonus1% GSTSale ReturnCheque/Online ReceivedBalanceReference
1300000711Jan-23Invoice AmountDR907481.25
1400001727Jan-23Invoice AmountDR51,408.00
15030Jan-23Received Online AmountDR200,000.00
16-31Jan-23Deduct Claim/Bonus AmountDR9804.75
170000223Feb-23Issued Invoice AmountDR19125.00
1800003117Feb-23Issued Invoice AmountDR215,424.00
1900004422Feb-23Issued Invoice AmountDR53550.00
20-28Feb-23Deduct Claim/Bonus AmountDR16745.21
210000592Mar-23Issued Invoice AmountDR99259.00
22-7Mar-23Received Online AmountDR140,000.00
2300008920Mar-23Issued Invoice AmountDR71375.00
2400010129Mar-23Issued Invoice AmountDR147,033.00
25-5Apr-23Deduct Claim/Bonus AmountDR43128.26
26-5Apr-23Received Online AmountDR186,000.00
27Total Amount1,564,655.25-69,678.22--526,000.00
28
ReCheck
Cell Formulas
RangeFormula
E13:E26E13=IF(OR(F13>0,G13>0,H13>0,I13>0,J13>0,K13>0), "DR", "CR")
F27F27=SUBTOTAL(109,[Invoice Issue])
G27G27=SUBTOTAL(109,[Credit Note])
H27H27=SUBTOTAL(109,[Claim/ Bonus])
I27I27=SUBTOTAL(109,[1% GST])
J27J27=SUBTOTAL(109,[Sale Return])
K27K27=SUBTOTAL(109,[Cheque/Online Received])


Actually I want to recheck the account so that there is no mistake. This file contains the following macro which is working fine and the result is in the "checking" sheet. I need another code that aggregates the data in the "Recheck" Sheet as I have shown above. Below code already work in workbook:-
VBA Code:
Sub CombineTables(loDest As ListObject, Optional lcSource As ListColumn)

Dim ws              As Worksheet
Dim lo              As ListObject
Dim lc              As ListColumn
Dim rDest           As Range
Dim lDestRows       As Long
Dim lSourceRows     As Long

Application.ScreenUpdating = False

If lcSource Is Nothing Then Set lcSource = loDest.ListColumns(1)
If loDest.ListRows.Count > 0 Then loDest.DataBodyRange.Delete

For Each ws In ActiveWorkbook.Worksheets
    For Each lo In ws.ListObjects
        If lo <> loDest Then
            With lo
                If InStr(.Name, loDest.Name & "_") > 0 Then
                    On Error Resume Next
                    lDestRows = loDest.ListRows.Count
                    On Error GoTo 0
                    lSourceRows = .ListRows.Count
                    If lSourceRows > 0 Then

                        'Work out where we want to paste the data to
                        Set rDest = loDest.HeaderRowRange.Offset(1 + lDestRows).Resize(lSourceRows)

                        'Resize the destination table
                        loDest.Resize loDest.Range.Resize(1 + lSourceRows + lDestRows)

                        For Each lc In .ListColumns
                         Intersect(loDest.ListColumns(lc.Name).Range.EntireColumn, rDest).Value2 = lc.DataBodyRange.Value
                        Next lc
                        Set lc = Nothing
                        On Error Resume Next
                        Set lc = .ListColumns(lcSource.Name)
                        On Error GoTo 0
                        If lc Is Nothing Then Intersect(lcSource.Range, rDest.EntireRow).Value2 = ws.Name
                    End If
                End If
            End With
        End If
    Next lo
Next ws

Application.ScreenUpdating = True

End Sub
Sub CombineTables_Caller()
CombineTables [Kalim].ListObject, [Kalim].ListObject.ListColumns("Source")
End Sub
 
Last edited:

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Try this:

VBA Code:
Sub recheck()
  Dim shR As Worksheet, sh As Worksheet
  Dim lstObj As ListObject, lo As ListObject
  Dim i As Long, lr As Long, lr2 As Long
 
  Application.ScreenUpdating = False
 
  Set shR = Sheets("ReCheck")
  On Error Resume Next
    Set lstObj = shR.ListObjects(1)
    lstObj.Unlist
  On Error GoTo 0
  shR.Rows("13:" & Rows.Count).Clear
   
  For i = 1 To 24
    Set sh = Sheets(CStr(i))
    Set lstObj = sh.ListObjects(1)
    lr = shR.Range("A:M").Find("*", , xlValues, xlPart, xlByRows, xlPrevious).Row + 1
    lstObj.DataBodyRange.Copy
    shR.Range("A" & lr).PasteSpecial xlPasteValues
    shR.Range("A" & lr).PasteSpecial xlPasteFormats
    lr2 = shR.Range("A:L").Find("*", , xlValues, xlPart, xlByRows, xlPrevious).Row
    shR.Range("M" & lr & ":M" & lr2).Value = sh.Name
  Next

  lr2 = shR.Range("A:M").Find("*", , xlValues, xlPart, xlByRows, xlPrevious).Row
  shR.Range("L13:L" & lr2).ClearContents
  shR.ListObjects.Add(xlSrcRange, shR.Range("A12:M" & lr2), , xlYes).Name = "Final"
  shR.ListObjects("Final").ShowTotals = True
  With shR.Range("E13:E" & lr2)
    .Formula = "=IF(OR(F13>0,G13>0,H13>0,I13>0,J13>0,K13>0), ""DR"", ""CR"")"
  End With
  For i = 6 To 12
    shR.ListObjects("Final").ListColumns(i).TotalsCalculation = xlTotalsCalculationSum
  Next
  shR.Range("M:M").NumberFormat = "General"
  shR.Range("A:M").EntireColumn.AutoFit
  Application.ScreenUpdating = True
  Application.CutCopyMode = False
End Sub


The macro includes formulas and subtotals.

--------------
Let me know the result and I'll get back to you as soon as I can.
Cordially
Dante Amor
--------------​
 
Upvote 0
Solution
Thank you very much sir I have no words to thank you🧡.

That it gave more surprising results than expected. I didn't expect to get an answer. But there are precious/sincere people like you in this world who populate it all. Thank you very much sir۔
 
Upvote 0

Forum statistics

Threads
1,215,095
Messages
6,123,072
Members
449,093
Latest member
ripvw

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