hello
I have this code works well based on headers but the problem I need matching the headers BRAND , BATCH and PR for all the files with file result1 and brings the values based on headers as in my file result1 in sheet before so i search so much to adapting the code what i need or search macro is close what i want in the internet but i don't find any thing
so i put the orginal data in sheet before and the expected result in sheet after in file result1 by the way it remains the file4 I can't upload because the limits 3 files but the file4 contains the values for purchase as in file result1 may be you ask me where did get the values from
finally i need some help to guide me how mod the code
Option Explicit
Sub Import_Source_File_Columns()
Dim sourceWb As Workbook, sourceSheet As Worksheet
Dim col As Long
Dim foundCol As Variant
Set sourceWb = Workbooks.Open(ThisWorkbook.Path & "\Source workbook.xlsx") 'CHANGE THIS
Set sourceSheet = sourceWb.Worksheets(1)
With ThisWorkbook.Worksheets(1)
For col = 1 To .Cells(1, .Columns.Count).End(xlToLeft).Column
foundCol = Application.Match(.Cells(1, col).Value, sourceSheet.Rows(1), 0)
If Not IsError(foundCol) Then
sourceSheet.Columns(foundCol).Copy .Columns(col)
Else
End If
Next
End With
sourceWb.Close SaveChanges:=False
End Sub
thanks in advance