Hi All-
I am currently working through a macro and got stuck about halfway. I have a number of files in a folder on my drive that I am pulling the first tab from into a Master workbook, and then I want to have a summary tab for all of those tabs(they are all identical). Some of the cells will be text(say range A5:C105), some will be SUM(E6:G105) and some will be AVERAGE(D6:D104) formulas needed. These formulas will not change, but will need to pull the data from all tabs that are pulled into the file.
So far I have this code that pulls all of the first tabs together:
I was going to record a macro that creates a summary table every time, but not sure if it is easier to create a blank template for the summary tab that will update every time all of the tabs are pulled into this file. The problem I ran across with that is that I will be taking the SUM of all tabs, but the number of tabs/name of tabs will be different.
Appreciate any help and can clarify if that didn't come across clearly. Thanks!!
I am currently working through a macro and got stuck about halfway. I have a number of files in a folder on my drive that I am pulling the first tab from into a Master workbook, and then I want to have a summary tab for all of those tabs(they are all identical). Some of the cells will be text(say range A5:C105), some will be SUM(E6:G105) and some will be AVERAGE(D6:D104) formulas needed. These formulas will not change, but will need to pull the data from all tabs that are pulled into the file.
So far I have this code that pulls all of the first tabs together:
Code:
Sub Staff_Plan_Update()
Dim wbDst As Workbook
Dim wbSrc As Workbook
Dim wsSrc As Worksheet
Dim MyPath As String
Dim strFilename As String
Call TimeStamp
Application.DisplayAlerts = False
Application.EnableEvents = False
Application.ScreenUpdating = False
MyPath = "C:\Users\Documents\Staff Plans\" ' change to current path
Set wbDst = Workbooks.Add(xlWBATWorksheet)
strFilename = Dir(MyPath & "\*.xlsx", vbNormal)
If Len(strFilename) = 0 Then Exit Sub
Do Until strFilename = ""
Set wbSrc = Workbooks.Open(Filename:=MyPath & "\" & strFilename)
Set wsSrc = wbSrc.Worksheets(1)
wsSrc.Copy After:=wbDst.Worksheets(wbDst.Worksheets.Count)
If Target = Range("A1") Then
Sheets(1).Name = Range("A1").Value
End If
wbSrc.Close False
strFilename = Dir()
Loop
wbDst.Worksheets(1).Delete
Application.DisplayAlerts = True
Application.EnableEvents = True
Application.ScreenUpdating = True
MsgBox ("Staff plan update is complete.")
End Sub
I was going to record a macro that creates a summary table every time, but not sure if it is easier to create a blank template for the summary tab that will update every time all of the tabs are pulled into this file. The problem I ran across with that is that I will be taking the SUM of all tabs, but the number of tabs/name of tabs will be different.
Appreciate any help and can clarify if that didn't come across clearly. Thanks!!