aravindhan_31
Well-known Member
- Joined
- Apr 11, 2006
- Messages
- 672
- Office Version
- 365
- 2019
- 2016
- Platform
- 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
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