allenayres83
New Member
- Joined
- Jan 19, 2021
- Messages
- 4
- Office Version
- 2016
- Platform
- Windows
I have workbook setup to use as a fieldbook for construction projects. The fieldbook will be organized by work item numbers (each work item will be a seperate worksheet). I have a folder setup that has a template for each work item and a summary in the main workbook that contains a list of work items for the project I am working on. I have a macro setup that will merge each work item that is in my summary from my templates folder to the main workbook. I have all of that working properly, but I need the macro to fill in some header information ,which can be found in the same row as the work item number, before it merges the next file. For example, Data!C11 has my item number. My macro will find that template (Lets say it is item number 201-01-00100) and merge it in to my workbook. I then want the macro to copy from Data!B11 to 201-01-00100!D3 and DataE11 to 201-01-00100!D4. Once that is done I want the macro to find the next template and carry on until the end of my list. Is that possible? Below is the current merge macro I am using. Thanks in advance
VBA Code:
Sub TestingMergeExcelFiles()
Dim vFiles As Variant, vFile As Variant
Dim wb As Workbook, ws As Worksheet
Dim n As Long
With Application
.ScreenUpdating = False
.Calculation = xlCalculationManual
End With
With ThisWorkbook.Worksheets("Summary")
vFiles = Application.Transpose(.Range("A4:A" & .Range("A4").End(xlDown).Row).SpecialCells(xlCellTypeConstants))
End With
For Each vFile In vFiles
Set wb = Workbooks.Open("C:\Users\d04m9\Desktop\test\" & vFile & ".xlsm")
For Each ws In wb.Worksheets
ws.Copy After:=ThisWorkbook.Sheets(ThisWorkbook.Sheets.Count)
n = n + 1
Next
wb.Close False
Next vFile
With Application
.ScreenUpdating = True
.Calculation = xlCalculationAutomatic
End With
MsgBox "Processed " & UBound(vFiles) & " files" & vbCrLf & "Merged " & n & " worksheets", Title:="Merge Excel files"
End Sub