Hi guys
Hope someone can help? I have experience with excel but not the VBA and macro side of excel. Basically I have 10 Teams each with their own excel workbook used to record daily figures. The last sheet on each workbook has their running total for the month. All I want is a new workbook that can copy the monthly table from each teams workbook into the new workbook for comparison. Does anyone know if this can be done? I was also hoping to be able to have sheets rename themselves based on data in a cell on the sheet itself? The monthly total sheets name would remain the same.
Thanks
Mark
Last edited by Gr8er1mark; 01-13-2012 at 01:58 PM. Reason: title change
Here's some code that you can adapt for your needs
Option Explicit '--------------------------------------------------------------------------------------- ' Module : Data ' Author : Roy Cox (royUK) ' Website : for more examples and Excel Consulting ' Date : 19/11/2011 ' Purpose : Combine data from several workbooks ' Disclaimer: Disclaimer; This code is offered as is with no guarantees. You may use it in your ' projects but please leave this header intact. '--------------------------------------------------------------------------------------- Option Explicit Sub CombineData() Dim oWbk As Workbook Dim uRng As Range Dim rToCopy As Range Dim rNextCl As Range Dim lCount As Long Dim bHeaders As Boolean Dim sFil As String Dim sPath As String With Application .ScreenUpdating = False .DisplayAlerts = False .EnableEvents = False ' On Error GoTo exithandler sPath = ThisWorkbook.Path & Application.PathSeparator & "Data" ChDir sPath sFil = Dir("*.xls") 'change or add formats Do While sFil <> "" 'will start LOOP until all files in folder sPath have been looped through With ThisWorkbook.Worksheets(1) Set uRng = .UsedRange If uRng.Cells.Count = 0 Then 'no data in master sheet bHeaders = False Else: bHeaders = True End If Set oWbk = Workbooks.Open(sPath & Application.PathSeparator & sFil) 'opens the file Set rToCopy = oWbk.ActiveSheet.UsedRange If Not bHeaders Then Set rNextCl = .Cells(1, 1) bHeaders = True Else: Set rNextCl = .Cells(.Rows.Count, 1).End(xlUp).Offset(1, 0) 'headers exist so don't copy Set rToCopy = rToCopy.Offset(1, 0).Resize(rToCopy.Rows.Count - 1, _ rToCopy.Columns.Count) End If rToCopy.Copy rNextCl End With oWbk.Close False 'close source workbook sFil = Dir Loop ' End of LOOP 'sort to remove empty rows Set uRng = ThisWorkbook.Worksheets(1).UsedRange uRng.Sort Key1:=.Range("A2"), Order1:=xlAscending, Header:=xlGuess, _ OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _ DataOption1:=xlSortNormal exithandler: .ScreenUpdating = True .DisplayAlerts = True .EnableEvents = True End With End Sub
Hope that helps.
RoyUK
--------
If you are pleased with a member's answer then use the Star icon to rate it, if you are pleased enough to part with cash consider a donation to Children in Need
For Excel Tips & Solutions, free examples and tutorials why not check out my downloads
New members please read & follow the Forum Rules
Remember to mark your questions Solved and rate the answer(s)
You need to do some reading on VBA then or stick to manually copying & pasting. With the information that you have provided you can only expect general help, we are here to help you learn, not provide custom code
Hope that helps.
RoyUK
--------
If you are pleased with a member's answer then use the Star icon to rate it, if you are pleased enough to part with cash consider a donation to Children in Need
For Excel Tips & Solutions, free examples and tutorials why not check out my downloads
New members please read & follow the Forum Rules
Remember to mark your questions Solved and rate the answer(s)
This is a duplicate post. There is another post from the same person - http://www.excelforum.com/excel-prog...o-another.html.
Cheers,
Arlette
If I 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]
Thanks Arlu.
Gr8er1mark
Don't waste our time with duplicate posts.
Hope that helps.
RoyUK
--------
If you are pleased with a member's answer then use the Star icon to rate it, if you are pleased enough to part with cash consider a donation to Children in Need
For Excel Tips & Solutions, free examples and tutorials why not check out my downloads
New members please read & follow the Forum Rules
Remember to mark your questions Solved and rate the answer(s)
Being new to forums and unsure of what is expected. You posted a message telling me the title was worng and did not comply. I changed the title and understood it that the original post was stopped and therefore re-posted it with a new heading. I am certainly not out to "waste time" and appreciate any help I can get.
Hi
I have been playing around with the sample code that you posted. But seem to be stuck. When I run it I get "Path Not Found" I think what I understand is that "sPath" set the directory to the directory my excel file is in? But even if I manual enter the directory after chDir (Instead of sPath) I still get the same result? Is there something I'm not doing?
Thanks
Mark
P.S How do I stop one of the threads seeing as there is now two?
Sorry forget the last bit. I noticed "& Data" that was being added to the path so I took it out. Still trying to work the rest out as seems to run with no errors but nothing copies over.
I've closed the other Thread.
As the code is set up now the files to copy from are ina sub folder of the folder that contains the master file. The sub folder is called Data
Hope that helps.
RoyUK
--------
If you are pleased with a member's answer then use the Star icon to rate it, if you are pleased enough to part with cash consider a donation to Children in Need
For Excel Tips & Solutions, free examples and tutorials why not check out my downloads
New members please read & follow the Forum Rules
Remember to mark your questions Solved and rate the answer(s)
Hi again
Got it working!Thank you. I took my sheet home from work home p.c uses excel 2010 as work p.c uses 2003 that wouldn`t make a difference would it? Only thing is it copies every sheet from every workbook I would like it to copy only one sheet from each called "Work Totals" is that possible? Thanks for your help so far ive been racking my brain with this for weeks.
Managed to get it sorted to take data from sheet 22 of the workbooks and it was working but now I am getting a runtime error 1004 "set method of range class failed" Any idea what the problem could be?
Thanks
Mark
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks