Hello Wizards
I have hit a bump in my quest to compile data from multiple files into 1 master file and am deferring to you for help. I am a VBA novice at best but am generally ok at modifying code I find in online searches but this one has me stumped. Before I show my specific problem I will elaborate on exactly what I am trying to do in case it helps you in helping me.
I have multiple “*FIT.xlsm” files which contain a common worksheet (“FIT Snapshot”), and am trying to create a macro that will:
Further macro details that I have yet to add to the code below are:
I have modified the below to open all the files, copy the data, and paste into my master but I am getting a syntax error once Sub CopyData is being called to run. I’m sure this is a simple fix but unfortunately my limited VBA knowledge is hindering my progress.
Any help/suggestions you folks may have is greatly appreciated.
Thank you again
I have hit a bump in my quest to compile data from multiple files into 1 master file and am deferring to you for help. I am a VBA novice at best but am generally ok at modifying code I find in online searches but this one has me stumped. Before I show my specific problem I will elaborate on exactly what I am trying to do in case it helps you in helping me.
I have multiple “*FIT.xlsm” files which contain a common worksheet (“FIT Snapshot”), and am trying to create a macro that will:
- Open through each “*FIT.xlsm” file in the specified folder
- Copy cells A2:BU12 from the “FIT Snaphot” worksheet in each “*FIT.xlsm” file
- Paste special value data into the next available row of the “Data Dump” worksheet within my master file
Further macro details that I have yet to add to the code below are:
- Upon opening each *FIT.xlsm file:
- Turn off auto calc
- Copy cell D1 from the “Data Dump” worksheet in my master file
- Paste Special Values into Cell D1 of the “FIT Snaphot” worksheet in the *FIT.xlsm file
- Calculate the “FIT Snaphot” worksheet so all formulas on this worksheet are updated
- Copy cells A2:BU12 from the “FIT Snaphot” worksheet
- Paste values into the next available row of the “Data Dump” worksheet within my master file
- FYI Row 1 is the header row so the 1st data set would be pasted into row A2.
- The macro would then loop through all “*FIT.xlsm” files within the folder to ensure all data is captured
- At end of macro a copy of the updated master file would be saved in the same folder designated to locate all of the “*FIT.xlsm” files with a time/date stamp in the file description.
I have modified the below to open all the files, copy the data, and paste into my master but I am getting a syntax error once Sub CopyData is being called to run. I’m sure this is a simple fix but unfortunately my limited VBA knowledge is hindering my progress.
Code:
Sub PullDataDump()
Dim wbTracker As Workbook
Dim shtData_Dump As Worksheet
Dim shtFIT_Snap As Worksheet
Dim strFilePath As String
Dim strPath As String
' Initialize some variables and
' get the folder path that has the files
Set shtData_Dump = ThisWorkbook.Sheets("Data Dump")
strPath = GetPath
' Make sure a folder was picked.
If Not strPath = vbNullString Then
' Get all the files from the folder
strfile = Dir$(strPath & "*FIT.xlsm", vbNormal)
Do While Not strfile = vbNullString
' Open the file and get the source sheet
Set wbTracker = Workbooks.Open(strPath & strfile)
Set shtFIT_Snap = wbTracker.Sheets("FIT Snapshot")
'Copy the data
Call CopyData(shtFIT_Snap, shtData_Dump)
'Close the workbook and move to the next file.
wbTracker.Close False
strfile = Dir$()
Loop
End If
End Sub
' Procedure to copy the data.
Sub CopyData(ByRef shtFIT_Snap As Worksheet, shtData_Dump As Worksheet)
Const strRANGE_ADDRESS As String = "A2:BU12"
Dim lRow As Long
'Determine the last row.
lRow = shtData_Dump.Cells(shtData_Dump.Rows.Count, 1).End(xlUp).Row + 1
'Copy the data.
shtFIT_Snap.Range(strRANGE_ADDRESS).Copy
shtData_Dump.Cells(1Row,1).PasteSpecial xlPasteValuesAndNumberFormats
' Reset the clipboard.
Application.CutCopyMode = xlCopy
End Sub
' Fucntion to get the folder path
Function GetPath() As String
With Application.FileDialog(msoFileDialogFolderPicker)
.ButtonName = "Select a folder"
.Title = "Folder Picker"
.AllowMultiSelect = False
'Get the folder if the user does not hot cancel
If .Show Then GetPath = .SelectedItems(1) & "\"
End With
End Function
Any help/suggestions you folks may have is greatly appreciated.
Thank you again