I tried doing that it is still not working. Attaching the file again to with the changes I made as suggested by you.
## Code in Sheet 1
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
End Sub
## Code in Module 1
Sub LinkedToSheet1()
Dim srcWB As Workbook, desWB As Workbook, desWS As Worksheet, lRow As Long, sPath As String, copyRng As Range
sPath = ThisWorkbook.Path & "\This_" & "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)
If MsgBox("Do you want to copy all the data from the source workbook or just a selected range? Click 'Yes' for all data or 'No' to select a range.", vbYesNo) = vbYes Then
Application.ScreenUpdating = False
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
Else
Application.ScreenUpdating = False
Set srcWB = Workbooks.Open(sPath)
Application.ScreenUpdating = True
Set copyRng = Application.InputBox(Prompt:="Select a range to copy.", Title:="Range Selection", Type:=8)
Application.ScreenUpdating = False
copyRng.Copy
desWS.Cells(desWS.Rows.Count, "A").End(xlUp).Offset(1).PasteSpecial
srcWB.Close False
Application.ScreenUpdating = True
End If
End Sub
Bookmarks