tmd63
New Member
- Joined
- Feb 21, 2014
- Messages
- 40
- Office Version
- 2013
- 2003 or older
- Platform
- Windows
Hi,
I am trying to write some code to load a sheet from another excel workbook into excel. But although I can open the file, I get a 400 error and the sheet does not copy.
Code:
Application.ScreenUpdating = False
Dim MyFile As String
MyFile = Application.GetOpenFilename()
Workbooks.Open (MyFile)
LastRow = Cells(Rows.Count, "A").End(xlUp).Row
Range("A1:P" & LastRow).Select
Selection.Copy
Application.DisplayAlerts = False
ActiveWorkbook.Close
Worksheets("CM11").Select
Range("A1").Select
Worksheets("CM11").Paste
It appears to be a fault at the LastRow line as the xlUp appears to start at -4162 and this returns a LastRow value of 1.
Can anyone enlighten me as to why the fault is happening.
(This is in an Excel 2003)
I am trying to write some code to load a sheet from another excel workbook into excel. But although I can open the file, I get a 400 error and the sheet does not copy.
Code:
Application.ScreenUpdating = False
Dim MyFile As String
MyFile = Application.GetOpenFilename()
Workbooks.Open (MyFile)
LastRow = Cells(Rows.Count, "A").End(xlUp).Row
Range("A1:P" & LastRow).Select
Selection.Copy
Application.DisplayAlerts = False
ActiveWorkbook.Close
Worksheets("CM11").Select
Range("A1").Select
Worksheets("CM11").Paste
It appears to be a fault at the LastRow line as the xlUp appears to start at -4162 and this returns a LastRow value of 1.
Can anyone enlighten me as to why the fault is happening.
(This is in an Excel 2003)