View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.misc
Terry Pinnell[_4_] Terry Pinnell[_4_] is offline
external usenet poster
 
Posts: 192
Default How to copy to a specific worksheet?

GS wrote:

Terry,
As with refs to a sheet (Sheets("Source")) where it refs a specific
sheet in the 'Sheets' collection of the active workbook, so too must
you ref a workbook! So...

Destination:=Workbooks("Walk Index").Sheets("TEMP").Range("C16")

..where workbooks is plural, and you omitted the dot before Sheets.

Note that in the case of Workbooks() you are referring to the workbooks
collection of the running instance of Excel. This means the file must
be open! If you want to read/write closed workbooks then that requires
using an ADODB recordset which involves a somewhat steep learning
curve. Alternatively, you can turn ScreenUpdating off and process
'behind-the-scene' but involves considerable overhead when doing
several files; -making the user wait until the process ends.


Thanks Garry. Made those two changes and 99% sure I've done so correctly
- but it still fails.

The source workbook 20160723-Day02-WH-Hoops-J-e560-m6.9.xlsm with its
single sheet 'Track Data' is open. So is the destination workbook Walk
Index.xlsm with its single (empty) sheet 'TEMP'. Whether I run from the
module or from Alt+F8 list, I get the same error. Here's the layout:

https://dl.dropboxusercontent.com/u/...Copying-01.jpg


Sub CopyTrackSheetCellsToWalkIndex()
' This fails. Run-time error '9': Subscript out of range

Sheets("Track Data").Range("B5").Copy Destination:=Workbooks("Walk
Index").Sheets("TEMP").Range("C16")

End Sub

Do I perhaps also have to identify the source workbook, even though it's
active when I run the macro?

Terry, East Grinstead, UK