Copy and paste this macro into the worksheet code module. Do the following: right click the tab name for your "New" sheet in the Master and click 'View Code'. Paste the macro into the empty code window that opens up. Close the code window to return to your sheet. Enter a month in cell W2 and press the ENTER key.
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.CountLarge > 1 Then Exit Sub
If Intersect(Target, Range("W2")) Is Nothing Then Exit Sub
Application.ScreenUpdating = False
Dim srcWB As Workbook, desWB As Workbook, desWS As Worksheet, lRow As Long, sPath As String
sPath = ThisWorkbook.Path & "\Report_" & Target.Value & ".xlsx"
If Len(Dir(sPath)) = 0 Then
MsgBox ("Source file " & sPath & " not found.")
Exit Sub
End If
Set desWB = ThisWorkbook
Set desWS = desWB.Sheets(1)
desWS.UsedRange.Offset(1).ClearContents
Set srcWB = Workbooks.Open(sPath)
With Sheets(1)
lRow = .Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
If lRow > 1 Then
.UsedRange.Offset(1).Copy desWS.Range("A2")
MsgBox ("Data appended from " & sPath & " to " & desWB.Name)
Else
MsgBox ("No data found in " & sPath)
End If
End With
srcWB.Close False
Application.ScreenUpdating = True
End Sub
Bookmarks