![]() |
|
#1
|
|||
|
|||
![]()
Hi Friends,
Kindly rectify the error in the below code. it will consolidate the diffrerent excel file data into one single file. error is getting into the below row. ______________________________ "ActiveSheet.Paste Destination = Worksheets("Sheet1"), Range(Cells(erow, 1), Cells(erow, 4))" ____________________ Sub copyDataFromMultipleWorkbooksintoMaster() Dim FolderPath As String, filepath As String, filename As String FolderPath = "c:\CONSOLIDATE\" filepath = FolderPath & "*.xls*" 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 ActiveSheet.Paste Destination = Worksheets("Sheet1"), Range(Cells(erow, 1), Cells(erow, 4)) filename = Dir ![]() Loop Application.DisplayAlerts = True End Sub |
#2
|
||||
|
||||
![]()
Please
1. Wrap code wth code tags 2. Post VBA questions in the "Programming forum". I moved them myself this time
__________________
Using O365 v2503 - Did you know you can thank someone who helped you? Click on the tiny scale in the right upper hand corner of your helper's post |
#3
|
||||
|
||||
![]()
There are many possible causes of error with your code. For example, it explicitly pastes into columns 1 to 4 but the data being copied don't necessarily span 4 columns...
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
![]() |
jonpackbosoxfan | Excel | 34 | 09-18-2013 08:38 AM |
![]() |
jmhultin | Outlook | 2 | 08-09-2013 02:01 PM |
Merge Excel files | Balas | Excel | 4 | 07-02-2012 06:09 AM |
![]() |
Kaloyanski | Excel | 3 | 11-02-2011 02:47 AM |