hi ,
Im new to VBA and I have been trying to create a program to copy specific range from multiple workbooks having data in sheet 2 to a master workbook sheet 2 .
COPY Condition: the column range will be A20 to AS20 while the row range will depend upon the last cell having data in column R.
PASTE Condition: consecutively all copied cells should be pasted with one blank row in between.
I came till the below stage, but no idea to proceed further. made some corrections but didnt work well.
Prog:
Im new to VBA and I have been trying to create a program to copy specific range from multiple workbooks having data in sheet 2 to a master workbook sheet 2 .
COPY Condition: the column range will be A20 to AS20 while the row range will depend upon the last cell having data in column R.
PASTE Condition: consecutively all copied cells should be pasted with one blank row in between.
I came till the below stage, but no idea to proceed further. made some corrections but didnt work well.
Prog:
VBA Code:
Sub copyDataFromMultipleWorkbooksIntoMaster()
Dim FolderPath As String, Filepath As String, Filename As String
FolderPath = "C:\Users\Desktop\combine\"
Filepath = FolderPath & "*.xlsx*"
Filename = Dir(Filepath)
Dim lastrow As Long, lastcolumn As Long
Do While Filename <> ""
Workbooks.Open (FolderPath & Filename)
lastrow = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Row
lastcolumn = ActiveSheet.Cells(1, Columns.Count).End(xlToLeft).Column
Range(Cells(2, 1), Cells(lastrow, lastcolumn)).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("Sheet1").Range(Cells(erow, 1), Cells(erow, lastcolumn))
Filename = Dir
Loop
Application.DisplayAlerts = True
End Sub