exceltadpole
Board Regular
- Joined
- Jan 14, 2004
- Messages
- 108
New to Excel. Trying to take copy a large data (values) from another workbook into current sheet with this code:
'--------------------------------
' open the source workbook and select the source sheet
Workbooks.Open Filename:="y:icontrol.xls"
Sheets("invSheet").Select
' copy the source range
Sheets("invSheet").Range("F4:I37150").Select
Selection.Copy
' select current workbook and paste the values starting at U4
Sheets("pnumSheet").Select
Sheets("pnumSheet").Range("U4:X37150").Select
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
' close the source workbook
Windows("icontrol.xls").Activate
ActiveWorkbook.Close
'--------------------------------
But at - Sheets("pnumSheet").Select
It gives
Run-time error '9':
Subscript out of range
The pnumSheet was already open and it contains the above code.
How this can be fixed? Please help.
The goal is to have the data values copied
from workbook icontrol.xls sheet invSheet range F4:I37150
to workbook qsys.xls sheet pnumSheet range U4:X37150
'--------------------------------
' open the source workbook and select the source sheet
Workbooks.Open Filename:="y:icontrol.xls"
Sheets("invSheet").Select
' copy the source range
Sheets("invSheet").Range("F4:I37150").Select
Selection.Copy
' select current workbook and paste the values starting at U4
Sheets("pnumSheet").Select
Sheets("pnumSheet").Range("U4:X37150").Select
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
' close the source workbook
Windows("icontrol.xls").Activate
ActiveWorkbook.Close
'--------------------------------
But at - Sheets("pnumSheet").Select
It gives
Run-time error '9':
Subscript out of range
The pnumSheet was already open and it contains the above code.
How this can be fixed? Please help.
The goal is to have the data values copied
from workbook icontrol.xls sheet invSheet range F4:I37150
to workbook qsys.xls sheet pnumSheet range U4:X37150