Hi,
try the files attached: support.zip
You'll have to adapt the file/sheet name and path of the sourcefile, if not open the macro will open the file and close it afterwards.
File contains in the worksheet module:
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
Dim xlWbSrc As Workbook, xlWsSrc As Worksheet
Dim xlCalulation As Long
On Error GoTo ErrorHandler
If Intersect(Target, Range("B4")) Is Nothing Then Exit Sub
With Application
.ScreenUpdating = False
.EnableEvents = False
.DisplayAlerts = False
xlCalulation = .Calculation
.Calculation = xlCalculationManual
End With
If WbOpen("Source.xlsx") Then
Set xlWbSrc = Workbooks("Source.xlsx") 'adapt filename
Else
Set xlWbSrc = Workbooks.Open(Filename:="X:\Documents\Programming\Excel\support\Source.xlsx") 'adapt path and filename
End If
If WsExists("SourceSheet", xlWbSrc) Then
Set xlWsSrc = xlWbSrc.Worksheets("SourceSheet")
Else
MsgBox "Worksheet 'SourceSheet' is missing in '" & xlWbSrc.Name & "'.", vbInformation + vbOKOnly, "Error"
GoTo ErrorHandler
End If
xlWsSrc.Range("A" & Range("D4").Value & ":AZ" & Range("E4").Value).Copy Destination:=Range("B7")
xlWbSrc.Close False
ErrorHandler:
If Err.Number <> 0 Then
MsgBox Err.Number & ": " & Err.Description, vbOKOnly + vbCritical, "Error"
End If
With Application
.ScreenUpdating = True
.EnableEvents = True
.DisplayAlerts = True
.Calculation = xlCalulation
End With
End Sub
and in a standard module
Function WsExists(ByVal wsName As String, Optional xlWb As Excel.Workbook) As Boolean
On Error Resume Next
Dim xlWs As Worksheet
If xlWb Is Nothing Then Set xlWb = ActiveWorkbook
Set xlWs = xlWb.Worksheets(wsName)
WsExists = (Err = 0)
Set xlWs = Nothing
End Function
Function WbOpen(ByVal wbName As String) As Boolean
On Error Resume Next
Dim xlWb As Workbook
Set xlWb = Application.Workbooks(wbName)
WbOpen = (Err = 0)
Set xlWb = Nothing
End Function
Bookmarks