I wonder whether someone may be able to help me please.
I'm using the code below to allow a user to merge multiple workbooks from different folders into one 'Summary' worksheet.
Sub Merge()
Dim DestWB As Workbook, WB As Workbook, WS As Worksheet, SourceSheet As String
Set DestWB = ActiveWorkbook
SourceSheet = "Input"
startrow = 7
FileNames = Application.GetOpenFilename( _
filefilter:="Excel Files (*.xls*),*.xls*", _
Title:="Select the workbooks to merge.", MultiSelect:=True)
If IsArray(FileNames) = False Then
If FileNames = False Then
Exit Sub
End If
End If
For n = LBound(FileNames) To UBound(FileNames)
Set WB = Workbooks.Open(Filename:=FileNames(n), ReadOnly:=True)
For Each WS In WB.Worksheets
If WS.Name = SourceSheet Then
With WS
If .UsedRange.Cells.Count > 1 Then
dr = DestWB.Worksheets("Input").Range("C" & DestWB.Worksheets("Input").Rows.Count).End(xlUp).Row + 1
Lastrow = .Range("C" & Rows.Count).End(xlUp).Row
If Lastrow >= startrow Then
.Range("A" & startrow & ":AE" & Lastrow).Copy
DestWB.Worksheets("Input").Cells(dr, "A").PasteSpecial xlValues
End If
End If
End With
Exit For
End If
Next WS
WB.Close savechanges:=False
Next n
End Sub
The code works, but I'd like to tweak this a little, so that instead of the user having to manually select the files to merge, the macro reads a list of the file names and file paths and automatically copies and pastes the relevant data into the "Summary" sheet.
I've set my Summary workbook up so there is a sheet called "Lists" with the file names listed in B3:B10 and in C3:C10 the associated file paths. I've searched "Stackoverflow" and carried out Google searches, and although I've found a number of posts on this topic, they don't show me how to read from a list of filenames and paths, but rather hard coding a specific directory which doesn't suit my needs.
I just wondered whether someone could possibly look at this please and offer some guidance on how I may be able to acheive this.
Many thanks and kind regards