Many tabs to 1

Zubair

Active Member
Joined
Jul 4, 2009
Messages
304
Office Version
  1. 2016
Platform
  1. Windows
Dear Experts,

I have flight sales for each day in a separate tab and the end of the month I need to bring all tabs in Summary Tab.

Need help to please with some VBA code please.

Shown below as a sample 2 days tabs and a summary tab.

Flights.xlsx
ABCDEFG
1Day No.Customer No.Customer NameCredit / Cash SaleFLT. NO.Receipt No.Quantity
211009EmiratesCashEK-6876002367800
311006SaudiCashSA-7126002450000
411008GermanCreditLH-8906002576000
511005PakistanCreditPK-2146002680000
621009EmiratesCashEK-6876002774000
721006SaudiCashSA-7126002882000
821008GermanCreditLH-8906002998000
921005PakistanCreditPK-2146003069000
Flight summary


Flights.xlsx
ABCDEFG
1Day No.Customer No.Customer NameCredit / Cash SaleFLT. NO.Receipt No.Quantity
211009EmiratesCashEK-6876002367800
311006SaudiCashSA-7126002450000
411008GermanCreditLH-8906002576000
511005PakistanCreditPK-2146002680000
Flight day 1


Flights.xlsx
ABCDEFG
1Day No.Customer No.Customer NameCredit / Cash SaleFLT. NO.Receipt No.Quantity
221009EmiratesCashEK-6876002774000
321006SaudiCashSA-7126002882000
421008GermanCreditLH-8906002998000
521005PakistanCreditPK-2146003069000
Flight day 2
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
Maybe like this
VBA Code:
Sub MM1()
 Dim lr As Long, ws As Worksheet
 lr = Sheets("Flight Summary").Cells(Rows.Count, "A").End(xlUp).Row
     For Each ws In Worksheets
            If ws.Name <> "Flight Summary" Then
                lr2 = ws.Cells(Rows.Count, "A").End(xlUp).Row
                 ws.Range("A2:G" & lr2).Copy Sheets("Flight Summary").Range("A" & lr)
                lr = Sheets("Flight Summary").Cells(Rows.Count, "A").End(xlUp).Row
            End If
    Next ws
End Sub
 
Upvote 1
Solution
Use Power Query. Assuming you have 1 table on every sheet, you can do it with one line of Power Query language.
Important is to use real tables instead of ranges.

Power Query:
let
    Source = Table.Combine(List.Skip(Excel.CurrentWorkbook()[Content]))
in
    Source

Book1
ABCDEFG
1Day No.Customer No.Customer NameCredit / Cash SaleFLT. NO.Receipt No.Quantity
211009EmiratesCashEK-6876002367800
311006SaudiCashSA-7126002450000
411008GermanCreditLH-8906002576000
511005PakistanCreditPK-2146002680000
Flight day 1


Book1
ABCDEFG
1Day No.Customer No.Customer NameCredit / Cash SaleFLT. NO.Receipt No.Quantity
221009EmiratesCashEK-6876002774000
321006SaudiCashSA-7126002882000
421008GermanCreditLH-8906002998000
521005PakistanCreditPK-2146003069000
Flight day 2


Result:

Book1
ABCDEFG
1Day No.Customer No.Customer NameCredit / Cash SaleFLT. NO.Receipt No.Quantity
211009EmiratesCashEK-6876002367800
311006SaudiCashSA-7126002450000
411008GermanCreditLH-8906002576000
511005PakistanCreditPK-2146002680000
621009EmiratesCashEK-6876002774000
721006SaudiCashSA-7126002882000
821008GermanCreditLH-8906002998000
921005PakistanCreditPK-2146003069000
Sheet1
 
Upvote 0
Use Power Query. Assuming you have 1 table on every sheet, you can do it with one line of Power Query language.
Important is to use real tables instead of ranges.

Power Query:
let
    Source = Table.Combine(List.Skip(Excel.CurrentWorkbook()[Content]))
in
    Source

Book1
ABCDEFG
1Day No.Customer No.Customer NameCredit / Cash SaleFLT. NO.Receipt No.Quantity
211009EmiratesCashEK-6876002367800
311006SaudiCashSA-7126002450000
411008GermanCreditLH-8906002576000
511005PakistanCreditPK-2146002680000
Flight day 1


Book1
ABCDEFG
1Day No.Customer No.Customer NameCredit / Cash SaleFLT. NO.Receipt No.Quantity
221009EmiratesCashEK-6876002774000
321006SaudiCashSA-7126002882000
421008GermanCreditLH-8906002998000
521005PakistanCreditPK-2146003069000
Flight day 2


Result:

Book1
ABCDEFG
1Day No.Customer No.Customer NameCredit / Cash SaleFLT. NO.Receipt No.Quantity
211009EmiratesCashEK-6876002367800
311006SaudiCashSA-7126002450000
411008GermanCreditLH-8906002576000
511005PakistanCreditPK-2146002680000
621009EmiratesCashEK-6876002774000
721006SaudiCashSA-7126002882000
821008GermanCreditLH-8906002998000
921005PakistanCreditPK-2146003069000
Sheet1
Also a good option to use Table, but the data operations team is sending is not in a table, 1st I need to convert all tabs in table than apply your given formula, which is time consuming, but I will definitely use this formula in some other similar cases.
 
Upvote 0
You could use VStack.

I do not know your sheet names.
You could put a blank sheet named Start in front of the relevant sheets and a blank sheet named End after all the relevant sheets.
Then a formula something like =VSTACK(Start:End!A2:M6) ; edit as appropriate.

The formula can be expanded to remove blanks.
 
Upvote 0
Maybe like this
VBA Code:
Sub MM1()
 Dim lr As Long, ws As Worksheet
 lr = Sheets("Flight Summary").Cells(Rows.Count, "A").End(xlUp).Row
     For Each ws In Worksheets
            If ws.Name <> "Flight Summary" Then
                lr2 = ws.Cells(Rows.Count, "A").End(xlUp).Row
                 ws.Range("A2:G" & lr2).Copy Sheets("Flight Summary").Range("A" & lr)
                lr = Sheets("Flight Summary").Cells(Rows.Count, "A").End(xlUp).Row
            End If
    Next ws
End Sub
Hi Michael,

I am getting the following result:

Missing:

1. Heading in "Flight Summary"
2. Row 5 of "Flight day 1"

What mistake I am doing ? I have copy/paste same VBA code

Flights.xlsx
ABCDEFG
111009EmiratesCashEK-6876002367800
211006SaudiCashSA-7126002450000
311008GermanCreditLH-8906002576000
421009EmiratesCashEK-6876002774000
521006SaudiCashSA-7126002882000
621008GermanCreditLH-8906002998000
721005PakistanCreditPK-2146003069000
Flight Summary
 
Upvote 0
@Zubair
Sorry, I assumed your Summary page already had a header row.
Try this
VBA Code:
Sub MM1()
 Dim lr As Long, lr2 as long, ws As Worksheet
Sheets("Flight Day 1") range("A1:G1") copy Sheets("Flight Summary").Range("A1")
 lr = Sheets("Flight Summary").Cells(Rows.Count, "A").End(xlUp).Row
     For Each ws In Worksheets
            If ws.Name <> "Flight Summary" Then
                lr2 = ws.Cells(Rows.Count, "A").End(xlUp).Row
                 ws.Range("A2:G" & lr2).Copy Sheets("Flight Summary").Range("A" & lr)
                lr = Sheets("Flight Summary").Cells(Rows.Count, "A").End(xlUp).Row+1
            End If
    Next ws
End Sub
 
Upvote 0
Oops typo
VBA Code:
Sub MM1()
 Dim lr As Long, lr2 as long, ws As Worksheet
Sheets("Flight Day 1") range("A1:G1") copy Sheets("Flight Summary").Range("A1")
 lr = Sheets("Flight Summary").Cells(Rows.Count, "A").End(xlUp).Row
     For Each ws In Worksheets
            If ws.Name <> "Flight Summary" Then
                lr2 = ws.Cells(Rows.Count, "A").End(xlUp).Row
                 ws.Range("A2:G" & lr2).Copy Sheets("Flight Summary").Range("A" & lr+1)
                lr = Sheets("Flight Summary").Cells(Rows.Count, "A").End(xlUp).Row
            End If
    Next ws
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,237
Messages
6,170,928
Members
452,366
Latest member
TePunaBloke

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