jmsla...@gmail.com
unread,Oct 11, 2021, 3:08:58 PM10/11/21You do not have permission to delete messages in this group
Sign in to report message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to
Hello,
Question and hopefully somebody can solve it :).
I've got a macro from the web which I use for merging from several files all sheets of them into one other file.
For example when I have;
- File1, SheetA, SheetB
- File2, SheetA, SheetB
The macro results in File3, SheetA, SheetB, SheetA(2), SheetB(2).
my whish is to change the macro is such a way that;
a) It select and copy from all files only a specific sheetname.
For example in the macro is mentioned 'SheetB' then it must copy only from all files the sheet with the name 'SheetB'.
b) It should copy from all selected Files/SheetB only from record 7 till last used record.
c) It should copy the selected data to ONE sheet ! That means that if the first sheet contains 1000 records then the copy of the next one should be paste at record 1000+1 and so on for the other files.
The actual 'normal' copy/merge macro is (see below);
Somebody can solve this. It should be great !! :)
regards, Johan
Sub MergeExcelFiles()
Dim fnameList, fnameCurFile As Variant
Dim countFiles, countSheets As Integer
Dim wksCurSheet As Worksheet
Dim wbkCurBook, wbkSrcBook As Workbook
fnameList = Application.GetOpenFilename(FileFilter:="Microsoft Excel Workbooks (*.xls;*.xlsx;*.xlsm),*.xls;*.xlsx;*.xlsm", Title:="Choose Excel files to merge", MultiSelect:=True)
If (vbBoolean <> VarType(fnameList)) Then
If (UBound(fnameList) > 0) Then
countFiles = 0
countSheets = 0
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
Set wbkCurBook = ActiveWorkbook
For Each fnameCurFile In fnameList
countFiles = countFiles + 1
Set wbkSrcBook = Workbooks.Open(Filename:=fnameCurFile)
For Each wksCurSheet In wbkSrcBook.Sheets
countSheets = countSheets + 1
wksCurSheet.Copy after:=wbkCurBook.Sheets(wbkCurBook.Sheets.Count)
Next
wbkSrcBook.Close SaveChanges:=False
Next
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
MsgBox "Processed " & countFiles & " files" & vbCrLf & "Merged " & countSheets & " worksheets", Title:="Merge Excel files"
End If
Else
MsgBox "No files selected", Title:="Merge Excel files"
End If
End Sub