Hello,
I have 60 excel files with single sheet and I want to merge all 60 files into one excel file with 60 tabs. Is there any way to do it with macros ??
Appreciate your help !!!
Thanks,
/Sukanya
Hello,
I have 60 excel files with single sheet and I want to merge all 60 files into one excel file with 60 tabs. Is there any way to do it with macros ??
Appreciate your help !!!
Thanks,
/Sukanya
I have a standard Consolidation macro to do this. Edit the lines marked in red to your needs and it should do what you want.
![]()
Option Explicit Sub Consolidate() 'Open all Excel files in a specific folder and import data as separate sheets 'Renames imported sheets to match workbook name of each source file 'JBeaucaire (7/6/2009) (2007 compatible) Dim strFileName As String, strPath As String Dim wbkOld As Workbook, wbkNew As Workbook, ws As Worksheet Application.ScreenUpdating = False Application.EnableEvents = False Application.DisplayAlerts = False Set wbkNew = ThisWorkbook strPath = "C:\Documents and Settings\Jerry\Files\" 'Edit to your path, be sure to end with \ If Left(strPath, 1) <> "\" Then strPath = strPath & "\" strFileName = Dir(strPath & "*.xl*") wbkNew.Activate 'Clear existing files (optional, remove this section if appending is desired) Worksheets.Add(After:=Worksheets(Worksheets.Count)).Name = "Temp" For Each ws In Worksheets If ws.Name <> "Temp" Then ws.Delete Next ws 'Import first active sheet from found file Do While Len(strFileName) > 0 Set wbkOld = Workbooks.Open(strPath & strFileName) ActiveSheet.Name = Left(strFileName, Len(strFileName) - 4) ActiveSheet.Copy After:=wbkNew.Sheets(wbkNew.Sheets.Count) strFileName = Dir wbkOld.Close False Loop wbkNew.Sheets("Temp").Delete Application.DisplayAlerts = True Application.EnableEvents = True Application.ScreenUpdating = True End Sub
Last edited by JBeaucaire; 02-03-2010 at 12:27 PM.
_________________
Microsoft MVP 2010 - Excel
Visit: Jerry Beaucaire's Excel Files & Macros
If you've been given good help, use theicon below to give reputation feedback, it is appreciated.
Always put your code between code tags. [CODE] your code here [/CODE]
?None of us is as good as all of us? - Ray Kroc
?Actually, I *am* a rocket scientist.? - JB (little ones count!)
Hi Forum,
Thanks so much for the code. It is working. Currently in the macro we have given a path to the files, so anyone using the macro has to create the same folders etc. I wanted to change it like once we run the macro it should ask for the path, like it should only point to dir and then we can select the path where the files are saved.
Also I want to clear the color (unfill) on the final workbook.
Is that possible ?
Thanks,
Abhilash
Last edited by Abhilash B; 07-06-2012 at 10:29 AM.
Of course, but are you 100% positive there will be no duplication of tab names between any two sheets? Absolutely 100%? It really makes me nervous opening 60 "unknown" files and moving in the only sheet in each and not using a sheet-naming method we know in advance won't result in duplicate sheet names.
Please advise.
I've highlighted in blue in my post above the line of code you could remove to have the sheets NOT be renamed prior to importing.
NOTE: Please don't use the QUOTE button, it duplicates my post completely inside of yours for no reason. Just use the QUICK REPLY box below. Use the QUOTE if you do want to quote something specific I've said, but only leave in that portion, remove the rest.
This makes thread much less cumbersome to read.
Last edited by JBeaucaire; 02-03-2010 at 12:28 PM.
Hi Jerry, you macro is very helpful. I have one quick question. what if I just want to combine all the files into one single work sheet ( a new file but all on one tab)?
Abhilash B,
Welcome to the Forum, unfortunately:
Your post does not comply with Rule 2 of our Forum RULES. Don't post a question in the thread of another member -- start your own thread. If you feel it's particularly relevant, provide a link to the other thread. It makes sense to have a new thread for your question because a thread with numerous replies can be off putting & difficult to pick out relevant replies.
If I have helped, Don't forget to add to my reputation (click on the star below the post)
Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
Use code tags when posting your VBA code: [code] Your code here [/code]
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks