Merge and Copy VBA

aliaslamy2k

Active Member
Joined
Sep 15, 2009
Messages
416
Office Version
  1. 2019
Platform
  1. Windows
I am creating an Assessment result database for candidates. When I download the report from the system, the reports are downloaded based on
designations. Therefore, there will be multiple reports I need to download.

I have a VBA that will merge all the files from the folder. I would like to modify the below VBA so it will merge all excel
files with their own file name as "Sheet Name" when it's merged.

After its merged, i want to copy data from all the sheets merged in one excel such as "First Name", "Last Name", "Email", "Position 'As Excel sheet name", "Invitation Date", "Completion Date", "Status", "Stage"

Please help me to write this code.

DOWNLOADED REPORT FORMAT

First nameLast nameEmailSourceInvitation dateCompletion dateStatusStageScoring benchmarkAverage scoreQualifying questionsCDP - Skills TestCommunicationEnglish (elementary/A2)Filled out only once from IP address?Webcam enabled?Full-screen mode always active?Mouse always in assessment window?Your ratingNotes about the candidate
PradipBiswasabcd@gmail.comInvitation by email2022/06/272022/06/29CompletedRejectedAll candidates2140320YesYesNoNo1Not all tests completed
MDAnisabcd@gmail.comInvitation by email2022/06/27InvitedNot yet evaluatedAll candidatesYesNoYesYes
MatiurRahmanabcd@gmail.comInvitation by email2022/06/27InvitedNot yet evaluatedAll candidatesYesNoYesYes
AnirbanDasabcd@gmail.comInvitation by email2022/06/27InvitedNot yet evaluatedAll candidatesYesNoYesYes
AtulGuptaabcd@gmail.comInvitation by email2022/06/27AddressedNot yet evaluatedAll candidatesYesNoYesYes
SouravGhoshabcd@gmail.comInvitation by email2022/06/27InvitedNot yet evaluatedAll candidatesYesNoYesYes
ShahrukKhanabcd@gmail.comInvitation by email2022/06/27InvitedNot yet evaluatedAll candidatesYesNoYesYes




DESIRED RESULT IN MASTER SHEET

First NameLast NameEmailPositionInvitation dateCompletion DateStatusStage



CURRENT VBA CODE

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
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"

Forum statistics

Threads
1,214,819
Messages
6,121,749
Members
449,050
Latest member
excelknuckles

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