Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 10-10-2015, 06:09 AM
Sandhya Sandhya is offline Merge the data from different excel files. Windows 7 32bit Merge the data from different excel files. Office 2007
Novice
Merge the data from different excel files.
 
Join Date: Nov 2014
Posts: 21
Sandhya is on a distinguished road
Smile Merge the data from different excel files.

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
Reply With Quote
  #2  
Old 10-10-2015, 08:14 AM
Pecoflyer's Avatar
Pecoflyer Pecoflyer is offline Merge the data from different excel files. Windows 7 64bit Merge the data from different excel files. Office 2010 64bit
Expert
 
Join Date: Nov 2011
Location: Brussels Belgium
Posts: 2,766
Pecoflyer has a brilliant futurePecoflyer has a brilliant futurePecoflyer has a brilliant futurePecoflyer has a brilliant futurePecoflyer has a brilliant futurePecoflyer has a brilliant futurePecoflyer has a brilliant futurePecoflyer has a brilliant futurePecoflyer has a brilliant futurePecoflyer has a brilliant futurePecoflyer has a brilliant future
Default

Please
1. Wrap code wth code tags
2. Post VBA questions in the "Programming forum". I moved them myself this time
__________________
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
Reply With Quote
  #3  
Old 10-10-2015, 02:53 PM
macropod's Avatar
macropod macropod is offline Merge the data from different excel files. Windows 7 64bit Merge the data from different excel files. Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

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]
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Merge the data from different excel files. Merge data from excel into word jonpackbosoxfan Excel 34 09-18-2013 08:38 AM
Merge the data from different excel files. Merge data files jmhultin Outlook 2 08-09-2013 02:01 PM
Merge Excel files Balas Excel 4 07-02-2012 06:09 AM
Merge the data from different excel files. How can I merge different excel files into one? Kaloyanski Excel 3 11-02-2011 02:47 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 01:15 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft