Data from multiple Sheets to be included in a single Main sheet, plus data added later to be updated in Main Sheet

Sumanmathew

Board Regular
Joined
Jan 25, 2021
Messages
65
Office Version
  1. 2021
  2. 2013
Platform
  1. Windows
Sir,
I have 3 sheets Sheet A, Sheet B and Sheet C and a |Main sheet.
I need the data in these 3 sheets to appear in the main sheet one below the other.
Again whenever I add new data in any of the individual sheet, it should be added in the Main sheet as well.
Like if a new item is added at the end of Sheet C, that should also appear in the Main Sheet.
Please help me solve this.

multiple sheet.xlsx
ABCD
4Sl.ItemAmount
51A11110
62A22220
73A33330
84A44440
95A55550
106A66660
117A77770
128A88880
139A99990
1410A1110100
15
16
Sheet A


multiple sheet.xlsx
ABCD
4Sl.ItemAmount
5101B111100
6102B222200
7103B333300
8104B444400
9105B555500
10106B666600
11107B777700
12108B888800
13109B999900
14110B11101000
15
Sheet B


multiple sheet.xlsx
ABCD
4Sl.ItemAmount
51001C1111000
61002C2222000
71003C3333000
81004C4444000
91005C5555000
101006C6666000
111007C7777000
121008C8888000
131009C9999000
141010C111010000
15
Sheet C


multiple sheet.xlsx
ABCD
3
4Sl.ItemAmount
5
6
7
8
9
10
11
12
13
14
15Subtotal
16Sl.ItemAmount
17
18
19
20
21
22
23
24
25
26
27Subtotal
28Sl.ItemAmount
29
30
31
32
33
34
35
36
37
38
39Subtotal
40Grand Total
41
Main
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
Please see if Power Query is available in your installation of 2013 Excel. It should be there.
You will be able to do what you do quite easily.
 
Upvote 0
Rethinking my statement. I don't think you can do subtotals inside of tables. So, back to the drawing board.

Can you have another summary sheet with a totals recap, versus a complete list with subtotals?
 
Upvote 0
Rethinking my statement. I don't think you can do subtotals inside of tables. So, back to the drawing board.

Can you have another summary sheet with a totals recap, versus a complete list with subtotals?
multiple sheet.xlsx
ABCD
3
4Sl.ItemAmount
5
6
7
8
9
10
11
12
13
14
15Subtotal550
16Sl.ItemAmount
17
18
19
20
21
22
23
24
25
26
27Subtotal5500
28Sl.ItemAmount
29
30
31
32
33
34
35
36
37
38
39Subtotal55000
40Grand Total61050
41
Main
Cell Formulas
RangeFormula
C15C15='Sheet A'!C15
C27C27='Sheet B'!C15
C39C39='Sheet C'!C15
C40C40=C15+C27+C39


Sir I have added the subtotals, is this what you meant?
 
Upvote 0
not really. I mean, if you use power query you will be using tables.
the combined appended power query result would be one big table that is easily refreshed when new data is keyed into the sub sheets.
but you cannot have subtotals inside of tables.

My question was ... do you need to see the detail above each subtotal?
 
Upvote 0
not really. I mean, if you use power query you will be using tables.
the combined appended power query result would be one big table that is easily refreshed when new data is keyed into the sub sheets.
but you cannot have subtotals inside of tables.

My question was ... do you need to see the detail above each subtotal?
Yes, all the rows in each of the sub sheets should come in the main sheet.
Again, whenever a new item is included in the sub sheets it should be upgraded in the Main sheet and the subtotal should also be upgraded.
 
Upvote 0
Using a Power Query function from this video, first bring in the three tables like this:
Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    AddedGroup = Table.AddColumn(Source, "Group", each Text.Start([Item],1), type text),
    ReorderedAmount = Table.ReorderColumns(AddedGroup,{"Sl.", "Item", "Group", "Amount"})
in
    ReorderedAmount
Do the same for Table2 and Table3.
Now open the Power Query editor and start a new blank query (I have no idea where that is for 2013 - in 365 it's Data -> Get Data -> From Other Sources -> Blank Query) named fxRowAndColTotal and enter this code:
Power Query:
let
    Source = ( InputTable as table, InitialColumnCount as number, optional AddColumnTotal as logical ) =>

let
    Cols = List.Skip(
                Table.ColumnNames(InputTable),
                InitialColumnCount ),

    InitialCols = List.FirstN(
                Table.ColumnNames(InputTable),
                InitialColumnCount ),

    TotalLabelAdded =  List.Accumulate(
                InitialCols,
                [],
                (s,c)=> Record.AddField(s, c, "Total") ),

    TotalRecord = List.Accumulate(
            Cols,
            TotalLabelAdded,
            (s,c)=> Record.AddField(s, c, List.Sum(Table.Column(InputTable, c))) ),

    RowTotal = Table.InsertRows(
                InputTable,
                Table.RowCount(InputTable), {TotalRecord} ),
  
    ColTotal = Table.AddColumn(
                RowTotal, "Col Total",
                each List.Sum(List.Select(Record.ToList(_), each _ is number)) )
in

    if AddColumnTotal = true then ColTotal else RowTotal
in
    Source
Finally, from the Power Query Home tab, select Append -> Append as New, select the three tables added to mash them all together, and then invoke the function above:
Power Query:
let
    Source = Table.Combine({Table1, Table2, Table3}),
    GroupedAllRows = Table.Group(Source, {"Group"}, {{"AllRows", each _, type table [#"Sl."=nullable number, Item=nullable text, Amount=nullable number, Group=text]}}),
    AddedCustom = Table.AddColumn(GroupedAllRows, "AddTotalToTables", each fxRowAndColTotal([AllRows], 3, true )),
    RemovedOtherColumns = Table.SelectColumns(AddedCustom,{"AddTotalToTables"}),
    ExpandedAddTotalToTables = Table.ExpandTableColumn(RemovedOtherColumns, "AddTotalToTables", {"Sl.", "Item", "Group", "Amount", "Col Total"}, {"Sl.", "Item", "Group", "Amount", "Col Total"}),
    RemovedColTotal = Table.RemoveColumns(ExpandedAddTotalToTables,{"Col Total"}),
    ChangedType = Table.TransformColumnTypes(RemovedColTotal,{{"Sl.", type text}, {"Item", type text}, {"Group", type text}, {"Amount", Int64.Type}}),
    ReplacedTotal = Table.ReplaceValue(ChangedType,"Total","",Replacer.ReplaceText,{"Sl.", "Item"}),
    ReplacedSubtotal = Table.ReplaceValue(ReplacedTotal,"Total","Subtotal",Replacer.ReplaceText,{"Group"})
in
    ReplacedSubtotal
to get this:
CombineSheets.xlsx
ABCD
1Sl.ItemGroupAmount
21A111A10
32A222A20
43A333A30
54A444A40
65A555A50
76A666A60
87A777A70
98A888A80
109A999A90
1110A1110A100
12Subtotal550
13101B111B100
14102B222B200
15103B333B300
16104B444B400
17105B555B500
18106B666B600
19107B777B700
20108B888B800
21109B999B900
22110B1110B1,000
23Subtotal5,500
241001C111C1,000
251002C222C2,000
261003C333C3,000
271004C444C4,000
281005C555C5,000
291006C666C6,000
301007C777C7,000
311008C888C8,000
321009C999C9,000
331010C1110C10,000
34Subtotal55,000
Report

If you don't want the Group column, use this code:
Power Query:
let
    Source = Table.Combine({Table1, Table2, Table3}),
    GroupedAllRows = Table.Group(Source, {"Group"}, {{"AllRows", each _, type table [#"Sl."=nullable number, Item=nullable text, Amount=nullable number, Group=text]}}),
    AddedCustom = Table.AddColumn(GroupedAllRows, "AddTotalToTables", each fxRowAndColTotal([AllRows], 3, true )),
    RemovedOtherColumns = Table.SelectColumns(AddedCustom,{"AddTotalToTables"}),
    ExpandedAddTotalToTables = Table.ExpandTableColumn(RemovedOtherColumns, "AddTotalToTables", {"Sl.", "Item", "Group", "Amount", "Col Total"}, {"Sl.", "Item", "Group", "Amount", "Col Total"}),
    RemovedColumns = Table.RemoveColumns(ExpandedAddTotalToTables,{"Group", "Col Total"}),
    ChangedType = Table.TransformColumnTypes(RemovedColumns,{{"Sl.", type text}, {"Item", type text}, {"Amount", Int64.Type}}),
    ReplacedTotal = Table.ReplaceValue(ChangedType,"Total","",Replacer.ReplaceText,{"Sl."}),
    ReplacedSubtotal = Table.ReplaceValue(ReplacedTotal,"Total","Subtotal",Replacer.ReplaceText,{"Item"})
in
    ReplacedSubtotal
Note that the columns to be totaled need to be at the end of the table, and the second parameter of the function is the number of columns to skip.
Just to be clear, the function is not mine, I got it from Goodly. Point being a search of YouTube or Google will usually point you in the right direction.
Hope that helps.
 
Last edited:
Upvote 0
VBA approach:
Assuming the Main sheet has headers in row 1, try:
VBA Code:
Sub UpdateMain()
    Application.ScreenUpdating = False
    Dim ws As Worksheet, wsName As Range, lRow As Long, srcRng As Range, rng As Range, lCol As Long, desWS As Worksheet
    Set desWS = Sheets("Main sheet")
    desWS.UsedRange.Offset(1).ClearContents
    For Each ws In Sheets
        If ws.Name <> "Main sheet" Then
            ws.UsedRange.Offset(1).Copy desWS.Cells(desWS.Rows.Count, "A").End(xlUp).Offset(1)
        End If
    Next ws
    Application.ScreenUpdating = True
End Sub
When you add new data in any of the individual sheets, just run the macro again to update the data in the main sheet.
 
Upvote 0
Using a Power Query function from this video, first bring in the three tables like this:
Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    AddedGroup = Table.AddColumn(Source, "Group", each Text.Start([Item],1), type text),
    ReorderedAmount = Table.ReorderColumns(AddedGroup,{"Sl.", "Item", "Group", "Amount"})
in
    ReorderedAmount
Do the same for Table2 and Table3.
Now open the Power Query editor and start a new blank query (I have no idea where that is for 2013 - in 365 it's Data -> Get Data -> From Other Sources -> Blank Query) named fxRowAndColTotal and enter this code:
Power Query:
let
    Source = ( InputTable as table, InitialColumnCount as number, optional AddColumnTotal as logical ) =>

let
    Cols = List.Skip(
                Table.ColumnNames(InputTable),
                InitialColumnCount ),

    InitialCols = List.FirstN(
                Table.ColumnNames(InputTable),
                InitialColumnCount ),

    TotalLabelAdded =  List.Accumulate(
                InitialCols,
                [],
                (s,c)=> Record.AddField(s, c, "Total") ),

    TotalRecord = List.Accumulate(
            Cols,
            TotalLabelAdded,
            (s,c)=> Record.AddField(s, c, List.Sum(Table.Column(InputTable, c))) ),

    RowTotal = Table.InsertRows(
                InputTable,
                Table.RowCount(InputTable), {TotalRecord} ),
 
    ColTotal = Table.AddColumn(
                RowTotal, "Col Total",
                each List.Sum(List.Select(Record.ToList(_), each _ is number)) )
in

    if AddColumnTotal = true then ColTotal else RowTotal
in
    Source
Finally, from the Power Query Home tab, select Append -> Append as New, select the three tables added to mash them all together, and then invoke the function above:
Power Query:
let
    Source = Table.Combine({Table1, Table2, Table3}),
    GroupedAllRows = Table.Group(Source, {"Group"}, {{"AllRows", each _, type table [#"Sl."=nullable number, Item=nullable text, Amount=nullable number, Group=text]}}),
    AddedCustom = Table.AddColumn(GroupedAllRows, "AddTotalToTables", each fxRowAndColTotal([AllRows], 3, true )),
    RemovedOtherColumns = Table.SelectColumns(AddedCustom,{"AddTotalToTables"}),
    ExpandedAddTotalToTables = Table.ExpandTableColumn(RemovedOtherColumns, "AddTotalToTables", {"Sl.", "Item", "Group", "Amount", "Col Total"}, {"Sl.", "Item", "Group", "Amount", "Col Total"}),
    RemovedColTotal = Table.RemoveColumns(ExpandedAddTotalToTables,{"Col Total"}),
    ChangedType = Table.TransformColumnTypes(RemovedColTotal,{{"Sl.", type text}, {"Item", type text}, {"Group", type text}, {"Amount", Int64.Type}}),
    ReplacedTotal = Table.ReplaceValue(ChangedType,"Total","",Replacer.ReplaceText,{"Sl.", "Item"}),
    ReplacedSubtotal = Table.ReplaceValue(ReplacedTotal,"Total","Subtotal",Replacer.ReplaceText,{"Group"})
in
    ReplacedSubtotal
to get this:
CombineSheets.xlsx
ABCD
1Sl.ItemGroupAmount
21A111A10
32A222A20
43A333A30
54A444A40
65A555A50
76A666A60
87A777A70
98A888A80
109A999A90
1110A1110A100
12Subtotal550
13101B111B100
14102B222B200
15103B333B300
16104B444B400
17105B555B500
18106B666B600
19107B777B700
20108B888B800
21109B999B900
22110B1110B1,000
23Subtotal5,500
241001C111C1,000
251002C222C2,000
261003C333C3,000
271004C444C4,000
281005C555C5,000
291006C666C6,000
301007C777C7,000
311008C888C8,000
321009C999C9,000
331010C1110C10,000
34Subtotal55,000
Report

If you don't want the Group column, use this code:
Power Query:
let
    Source = Table.Combine({Table1, Table2, Table3}),
    GroupedAllRows = Table.Group(Source, {"Group"}, {{"AllRows", each _, type table [#"Sl."=nullable number, Item=nullable text, Amount=nullable number, Group=text]}}),
    AddedCustom = Table.AddColumn(GroupedAllRows, "AddTotalToTables", each fxRowAndColTotal([AllRows], 3, true )),
    RemovedOtherColumns = Table.SelectColumns(AddedCustom,{"AddTotalToTables"}),
    ExpandedAddTotalToTables = Table.ExpandTableColumn(RemovedOtherColumns, "AddTotalToTables", {"Sl.", "Item", "Group", "Amount", "Col Total"}, {"Sl.", "Item", "Group", "Amount", "Col Total"}),
    RemovedColumns = Table.RemoveColumns(ExpandedAddTotalToTables,{"Group", "Col Total"}),
    ChangedType = Table.TransformColumnTypes(RemovedColumns,{{"Sl.", type text}, {"Item", type text}, {"Amount", Int64.Type}}),
    ReplacedTotal = Table.ReplaceValue(ChangedType,"Total","",Replacer.ReplaceText,{"Sl."}),
    ReplacedSubtotal = Table.ReplaceValue(ReplacedTotal,"Total","Subtotal",Replacer.ReplaceText,{"Item"})
in
    ReplacedSubtotal
Note that the columns to be totaled need to be at the end of the table, and the second parameter of the function is the number of columns to skip.
Just to be clear, the function is not mine, I got it from Goodly. Point being a search of YouTube or Google will usually point you in the right direction.
Hope that helps.
Thankyou for your reply, please let me try it.
 
Upvote 0
I missed the subtotals and grand total in my previous post. Please try:
VBA Code:
Sub UpdateMain()
    Application.ScreenUpdating = False
    Dim ws As Worksheet, lRow As Long, lRow2 As Long, desWS As Worksheet
    Set desWS = Sheets("Main sheet")
    desWS.UsedRange.Offset(1).ClearContents
    For Each ws In Sheets
        If ws.Name <> "Main sheet" Then
            With desWS
                lRow = .Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
                If lRow = 1 Then
                    ws.UsedRange.Offset(1).Copy .Range("A2")
                    lRow2 = .Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
                    .Range("B" & lRow2 + 1) = "Subtotal"
                    .Range("C" & lRow2 + 1) = WorksheetFunction.Sum(.Range("C2:C" & lRow2))
                Else
                    lRow = .Columns(2).Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
                    ws.UsedRange.Offset(1).Copy .Range("A" & lRow + 1)
                    lRow2 = .Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
                    .Range("B" & lRow2 + 1) = "Subtotal"
                    .Range("C" & lRow2 + 1) = WorksheetFunction.Sum(.Range("C" & lRow + 1 & ":C" & lRow2))
                End If
            End With
        End If
    Next ws
    With desWS
        lRow = .Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
        .Range("B" & lRow + 1) = "Grand Total"
        .Range("C" & lRow + 1) = WorksheetFunction.Sum(.Range("C2:C" & lRow))
    End With
    Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,368
Messages
6,124,520
Members
449,169
Latest member
mm424

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