Forum Discussion

B Picazo's avatar
B Picazo
Copper Contributor
Nov 12, 2017

Consolidating all worksheets (different workbook) into one workbook

Hi,

 

I've quite new in using macro and have only  learned via blogs/youtube.

 

I've been using this macro to consolidate my data from different workbooks into one. However, if a cell is hidden, the hidden cells are not considered in the count of cells to be copied (ex. copy A1 to D1, but C1 is hidden, it will copy A1,B1,D1 & E1 instead).

 

Sub copyDataFromMultipleWorkbooksIntoMaster()

Dim FolderPath As String, filepath As String, filename As String

FolderPath = "C:\Users\bbp\Desktop\Excel Conso\"

filepath = FolderPath & "*.xlsx"

filename = Dir(filepath)

Dim lastrow As Long, lastcolumn As Long

Do While filename <> ""
Workbooks.Open (FolderPath & filename)
Range("A4:AL4").Copy
lastrow = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Row
lastcolumn = ActiveSheet.Cells(1, Columns.Count).End(xlToLeft).Column
Range(Cells(4, 1), Cells(lastrow, 38)).Copy
Application.DisplayAlerts = False
ActiveWorkbook.Close

erow = Sheet1.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
lastcolumn = ActiveSheet.Cells(1, Columns.Count).End(xlToLeft).Column
ActiveSheet.Paste Destination:=Worksheets("Sheet 1").Range(Cells(erow, 1), Cells(erow, 38))

filename = Dir

Loop

End Sub

 

Hope you could help me.

 

Thank you.

Resources