Merge data from multiple workbooks and sheets

aravindhan_31

Well-known Member
Joined
Apr 11, 2006
Messages
672
Office Version
  1. 365
  2. 2019
  3. 2016
Platform
  1. Windows
Hi,

I have 12 workbooks called Jan, Feb, Mar etc.. all these files have 5 sheets each namely sht1, sht2, sht3, sht4 & sht5 .
Now I want to consolidated all the 12 files into one, that is take sht1 data from all those 12 files and put into sht1 only below the other, similarly for sht2 , sht3 etc.
I have a code that consolidates data from the sheet name "Sht1", but not sure how to loop through all the sheets
Code:
Sub CreateDatedReport_completed()
Dim wbNew As Workbook
Dim wsRpt As Worksheet:     Set wsRpt = ThisWorkbook.Sheets("Sht1")
Dim NR As Long
Dim LR As Long
Dim fPath As String:        fPath = "D:\Macros\Macros arvind\Macros arvind\CP\Hari\Tracker\"    'don't forget the final \
Dim fName As String
'Option to clear existing report

        NR = Range("C" & Rows.Count).End(xlUp).Row + 1

'Start import loop
    Application.ScreenUpdating = False
    fName = Dir(fPath & "*.xls")
    
    Do While Len(fName) > 0
      'open file
        Set wbNew = Workbooks.Open(fPath & fName)
      'apply autofilter
      Sheets("Productivity").Select
            LR = Range("C" & Rows.Count).End(xlUp).Row
            If LR > 1 Then _
    Range("A11:AP" & LR).Select
                 Selection.Copy
                wsRpt.Range("A" & NR).PasteSpecial xlPasteValues
      
        wbNew.Activate
      'close
        wbNew.Close False
        
      'next loop
        NR = Range("C" & Rows.Count).End(xlUp).Row + 1
        fName = Dir
    Loop
    Sheets("Sht1").Select
Application.ScreenUpdating = True
End Sub
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.

Forum statistics

Threads
1,224,603
Messages
6,179,850
Members
452,948
Latest member
UsmanAli786

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