I would want the file names to be recorded in the "MasterFile" next to the data pulled from the respective files, so that i can map data items to the file names.
Any guidance/ ideas are much appreciated!! Thanks in advance :)
Code:
Sub PIDataExtraction()
Dim myFile As String, Path As String
Dim erow As Long, col As Long
Dim shtSrc As Worksheet
Dim copyrange As Range, cel As Range
fpath = Range("B2").Value
myFile = Dir(Path & "*.xl??")
Application.ScreenUpdating = False
Do While myFile <> ""
Workbooks.Open (Path & myFile)
Windows(myFile).Activate
On Error Resume Next
Set shtSrc = Worksheets("RX Ratings Price Calculator")
If err = 9 Then
On Error Resume Next
Set shtSrc = Worksheets("Feed Content Pricing Guideline")
If err = 9 Then Exit Sub
On Error GoTo 0
End If
Set copyrange = shtSrc.Range("B4,E7,E9,E11,E13,E15,Ratings_Universe_Default,J22,C24,C25,C26,I11,R16")
Windows("MasterFile.xlsm").Activate
erow = Data.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
col = 1
For Each cel In copyrange
Cells(erow, col).Value = cel.Value
col = col + 1
Next
Windows(myFile).Close savechanges:=False
myFile = Dir()
Loop
Range("A:E").EntireColumn.AutoFit
Application.DisplayAlerts = True
Application.ScreenUpdating = True
MsgBox "Data has been Compiled,Please Check!"
End Sub