My code below browses through the folder and effectively picks out the required files but the copy paste codes that I have tried did not work for me. Cant use traditional copy paste as column order is not same. Column names are same though.
Sub ImportExcelfiles() Dim strPath As String Dim strFile As String Dim wbSource As Workbook Dim wsSource As Worksheet Dim wsTarget As Worksheet Dim bookName As Worksheet Dim rowCountSource As Long Dim colCountSource As Long Dim rowOutputTarget As Long Dim colOutputTarget As Long 'Variables for Sheet - Workbook Name Dim nameCount As Long Dim fileName As String Application.DisplayAlerts = False Application.ScreenUpdating = False '==================================== 'SET THE PATH AND FILE TO THE FOLDER '==================================== strPath = ThisWorkbook.Worksheets("Control").Range("C4") fileName = ThisWorkbook.Worksheets("Control").Range("C5") If Right(strPath, 1) <> "\" Then strPath = strPath & "\" 'set the target worksheet Set wsTarget = ThisWorkbook.Worksheets("Master Data") Set bookName = ThisWorkbook.Worksheets("Workbook Name") 'set the initial output row and column count for master data and workbook name rowOutputTarget = 2 nameCount = 2 'get the first file strFile = Dir(strPath & "*.xlsx*") 'loop throught the excel files in the folder Do While strFile <> "" If InStr(strFile, fileName) > 0 Then 'open the workbook Set wbSource = Workbooks.Open(strPath & strFile) Set wsSource = wbSource.Worksheets("Details") 'get the row and column counts With wsSource 'row count based on column 1 = A rowCountSource = .Cells(.Rows.Count, 1).End(xlUp).Row 'column count based on row 1 colCountSource = .Cells(1, .Columns.Count).End(xlToLeft).Column End With -------------------------------Need help here to copy paste------------------------------------- 'copy and paste from A2 wsSource.Range("A3", "AD" & rowCountSource).Copy wsTarget.Range("A" & rowOutputTarget).PasteSpecial Paste:=xlPasteValues bookName.Range("A" & nameCount).Value = wbSource.Name nameCount = nameCount + 1 rowOutputTarget = rowOutputTarget + rowCountSource - 2 'close the opened workbook wbSource.Close SaveChanges:=False End If 'get the next file strFile = Dir() Loop End Sub