Sub GetData()
Dim sBk As Workbook, rBk As Workbook
Dim sSh As Worksheet, rSh As Worksheet
Dim msg As String, fName As String
Set rBk = ThisWorkbook
msg = "Enter the name of the workbook containing the data you want to copy."
fName = InputBox(msg)
If fName = "" Then Exit Sub
If InStr(1, fName, ".xls") > 0 Then
If WorkbookOpen(fName) Then Set sBk = Workbooks(fName)
Else
If WorkbookOpen(fName & ".xls") Then
Set sBk = Workbooks(fName & ".xls")
Else
MsgBox "Open the workbook " & fName & " and then run this macro again"
Exit Sub
End If
End If
With sBk.Sheets("Data for Graphs")
.Range("A6:W14").Copy
End With
With rBk.Sheets("Sheet1") 'Change sheet name in destination workbook to suit
.Range("A19").PasteSpecial Paste:=xlValues
End With
Application.CutCopyMode = False
End Sub
Function WorkbookOpen(WorkBookName As String) As Boolean
' returns TRUE if the workbook is open
WorkbookOpen = False
On Error GoTo WorkBookNotOpen
If Len(Application.Workbooks(WorkBookName).Name) > 0 Then
WorkbookOpen = True
Exit Function
End If
WorkBookNotOpen:
End Function