View Single Post
  #1   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?

First, a reminder that I've long since lost what little VBA know-how I
had around 15-20 years ago, so basically I'm a novice.

Cut to the essentials, I want to copy cell B5 from one worksheet to C16
of another worksheet in another workbook.

I found this example of copying between worksheets:

http://analysistabs.com/excel-vba/co...et-to-another/

So thought I'd start with that simpler situation. I therefore first
opened Excel 365 and a new file (workbook?) called My Book 1.xlsm. I
then named two tabs (sheets) 'Source' and 'Destination' respectively. In
Source I typed 'Cell B5' into B5 and left Destination empty. I wrote the
following code:

Sub CopyBetweenWorksheetsInSameBook()

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

End Sub

I ran it with F5 and it worked as expected.

Then I edited the macro to use one of my actual workbooks, adding two
sheets and using this code:

Sub CopyBetweenWorksheetsInSameBook()

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

End Sub

That also worked OK. So I then tried to rewrite the macro to copy to a
specified different destination workbook. The file is called Walk
Index.xlsm and it's in the same folder as the source workbook. But this
didn't work:

Sub CopyTrackSheetCellsToWalkIndex()

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

End Sub

Could someone put me straight on specifying the workbook and its
worksheet please?

Terry, East Grinstead, UK