Merging multiple worksheets into one workbook from a list

allenayres83

New Member
Joined
Jan 19, 2021
Messages
4
Office Version
  1. 2016
Platform
  1. 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
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.

Forum statistics

Threads
1,215,094
Messages
6,123,071
Members
449,092
Latest member
ipruravindra

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top