Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
 
Posts: n/a
Default How copy cell workbook to workbook?

Can someone tell me why this isn't copying cell 2,3 in 2nd workbook to
cell 5,2 in 1st workbook? It prints the msgbox properly and runs w/o
runtime errors.

Sub Copy_Cell_from_2ndbook_to_1st_book()
Workbooks(1).Worksheets(1).Cells(5, 2).Value =
Workbooks(2).Worksheets(1).Cells(2, 3).Value
MsgBox "Done"
End Sub

Thanks!

  #2   Report Post  
Gary''s Student
 
Posts: n/a
Default How copy cell workbook to workbook?

I don't see where the arrays Workbooks() and Worksheets() are set.
--
Gary''s Student


" wrote:

Can someone tell me why this isn't copying cell 2,3 in 2nd workbook to
cell 5,2 in 1st workbook? It prints the msgbox properly and runs w/o
runtime errors.

Sub Copy_Cell_from_2ndbook_to_1st_book()
Workbooks(1).Worksheets(1).Cells(5, 2).Value =
Workbooks(2).Worksheets(1).Cells(2, 3).Value
MsgBox "Done"
End Sub

Thanks!


  #3   Report Post  
Jack Sons
 
Posts: n/a
Default How copy cell workbook to workbook?

Write Workbooks1 in stead of Workbooks(1) and Sheets1 in stead of
Worksheets(1) etc.

HTH

Jack Sons
The Netherlands

schreef in bericht
ups.com...
Can someone tell me why this isn't copying cell 2,3 in 2nd workbook to
cell 5,2 in 1st workbook? It prints the msgbox properly and runs w/o
runtime errors.

Sub Copy_Cell_from_2ndbook_to_1st_book()
Workbooks(1).Worksheets(1).Cells(5, 2).Value =
Workbooks(2).Worksheets(1).Cells(2, 3).Value
MsgBox "Done"
End Sub

Thanks!



  #4   Report Post  
Dave Peterson
 
Posts: n/a
Default How copy cell workbook to workbook?

How would you ever know which workbook is workbooks(1) and which is
workbooks(2)?

I think I'd be much more specific (well, if it's possible)

Sub Copy_Cell_from_2ndbook_to_1st_book()
Workbooks("book1.xls").Worksheets(1).Cells(5, 2).Value = _
Workbooks("book2.xls").Worksheets(1).Cells(2, 3).Value
MsgBox "Done"
End Sub

or even...

Sub Copy_Cell_from_2ndbook_to_1st_book()
Workbooks("book1.xls").Worksheets("sheet1").Cells( 5, 2).Value = _
Workbooks("book2.xls").Worksheets("sheet1").Cells( 2, 3).Value
MsgBox "Done"
End Sub

I'm betting that your code worked perfectly--it just didn't do it to the
workbooks you wanted.

adding:

msgbox workbooks(1).worksheets(1).range("B5").address(ext ernal:=true) _
& vblf & workbooks(2).worksheets(1).range("C2").address(ext ernal:=true)

might give you a clue on what got changed.

wrote:

Can someone tell me why this isn't copying cell 2,3 in 2nd workbook to
cell 5,2 in 1st workbook? It prints the msgbox properly and runs w/o
runtime errors.

Sub Copy_Cell_from_2ndbook_to_1st_book()
Workbooks(1).Worksheets(1).Cells(5, 2).Value =
Workbooks(2).Worksheets(1).Cells(2, 3).Value
MsgBox "Done"
End Sub

Thanks!


--

Dave Peterson
  #5   Report Post  
JE McGimpsey
 
Posts: n/a
Default How copy cell workbook to workbook?

They're not arrays, they're collections.

See the "Workbooks Collection Object" and "Worksheets Collection Object"
entries in XL/VBA Help.

In article ,
Gary''s Student wrote:

I don't see where the arrays Workbooks() and Worksheets() are set.
--
Gary''s Student


" wrote:

Can someone tell me why this isn't copying cell 2,3 in 2nd workbook to
cell 5,2 in 1st workbook? It prints the msgbox properly and runs w/o
runtime errors.

Sub Copy_Cell_from_2ndbook_to_1st_book()
Workbooks(1).Worksheets(1).Cells(5, 2).Value =
Workbooks(2).Worksheets(1).Cells(2, 3).Value
MsgBox "Done"
End Sub

Thanks!



  #6   Report Post  
 
Posts: n/a
Default How copy cell workbook to workbook?

Thanks Dave + others,

"How would you ever know which workbook is workbooks(1) and which is
workbooks(2)? " was a good question / point.

I was also copying the wrong cells. The working code is now:

Sub Copy_Cell_from_2ndbook_to_1st_book()

' Copy 2nd book's B2 (2,2) to 1st book's E2 (2,5)
Workbooks("Book1.xls").Worksheets("sheet1").Cells( 2, 5).Value = _
Workbooks("counts.csv").Worksheets("summary").Cell s(2, 2).Value

MsgBox "Done"

End Sub

  #7   Report Post  
Dave Peterson
 
Posts: n/a
Default How copy cell workbook to workbook?

This portion of your code looks suspicious:
Workbooks("counts.csv").Worksheets("summary").Cell s(2, 2).Value
When I open a .CSV file, the worksheet name is based on that file name.

If you change that worksheet name to Summary, then ignore this.

But this is one time I would use:
Workbooks("counts.csv").Worksheets(1).Cells(2, 2).Value
to get that first (and only) worksheet in the .CSV file.

wrote:

Thanks Dave + others,

"How would you ever know which workbook is workbooks(1) and which is
workbooks(2)? " was a good question / point.

I was also copying the wrong cells. The working code is now:

Sub Copy_Cell_from_2ndbook_to_1st_book()

' Copy 2nd book's B2 (2,2) to 1st book's E2 (2,5)
Workbooks("Book1.xls").Worksheets("sheet1").Cells( 2, 5).Value = _
Workbooks("counts.csv").Worksheets("summary").Cell s(2, 2).Value

MsgBox "Done"

End Sub


--

Dave Peterson
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
hpw do I logic test a cell then copy the row to diff. SS Debi Excel Worksheet Functions 4 October 5th 05 09:42 PM
copying cell names Al Excel Discussion (Misc queries) 12 August 11th 05 03:01 PM
Copy cell format to cell on another worksht and update automatical kevinm Excel Worksheet Functions 21 May 19th 05 11:07 AM
How can I copy a cell from one page to all pages of a workbook? John Q Excel Worksheet Functions 2 April 12th 05 08:32 PM
GET.CELL Biff Excel Worksheet Functions 2 November 24th 04 07:16 PM


All times are GMT +1. The time now is 04:32 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"