allenayres83
New Member
- Joined
- Jan 19, 2021
- Messages
- 4
- Office Version
- 2016
- Platform
- Windows
The code below merges some excel templates into a single workbook from a list on my "Data" worksheet and fills out some header information that also comes from "Data". This data can be updated from time to time and new items added to the list. Some of the information in the old items can be updated also. Can this code be modified to only merge in the new items that were added to the list and update the header information on all old and new worksheets.
VBA Code:
Enum ReadColumns
rcLineItem = 2
rcItemCode = 3
rcUnits = 6
rcSupplementalDescription = 4
rcUnitPrice = 5
rcOriginalPlanQuantity = 7
rcCurrentPlanQuantity = 8
rcCategory = 1
End Enum
Sub MergeandFillHeader()
Dim v As Variant, i As Long
Dim wb As Workbook, n As Long
With Application
.ScreenUpdating = False
.Calculation = xlAutomatic
End With
With ThisWorkbook
v = .Worksheets("Data").Range("C11").CurrentRegion.Value
For i = 3 To UBound(v)
If Not v(i, rcItemCode) = vbNullString Then
Set wb = Workbooks.Open(.Worksheets("Merge").Range("D5").Value & "\" & v(i, rcItemCode) & ".xlsm")
wb.Sheets(1).Copy After:=.Sheets(.Sheets.Count)
With .Sheets(.Sheets.Count)
.Cells(1, 4).Value = Worksheets("Merge").Range("D3").Value
.Cells(2, 4).Value = v(i, rcItemCode)
.Cells(3, 4).Value = v(i, rcCategory)
.Cells(4, 4).Value = v(i, rcLineItem)
.Cells(5, 4).Value = v(i, rcSupplementalDescription)
.Cells(6, 4).Value = v(i, rcUnits)
.Cells(7, 4).Value = v(i, rcOriginalPlanQuantity)
.Cells(8, 4).Value = v(i, rcCurrentPlanQuantity)
.Cells(10, 4).Value = v(i, rcUnitPrice)
End With
n = n + 1
wb.Close False
End If
Next i
End With
With Application
.ScreenUpdating = True
.Calculation = xlCalculationAutomatic
End With
MsgBox "Processed " & n & " files", Title:="Merge Excel files"
End Sub