Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Paste cells from one workbook to another

Hi all,

I'm new to VBA programming and I have what should be a simple question
for you experts!

Basically, I have 2 workbooks and I want to copy a range of cells from
Workbook A and paste them in Workbook B. I am getting a 'subscript out
of range' error when I try to pase and I cannot figure out why. Below
you will find the code that I am using:

Set wbDest = ActiveWorkbook
Set wbSource = Workbooks.Open(cdbBrowse.Filename)
wbSource.Worksheets("Sheet1").Range("A9:E13").Copy
Destination:=wbDest.Worksheets("Sheet1").Range("A9 :E13")

I know the problem is something with the Destination because if I just
do the Copy statement with no destination, I get no error.

Also, right now I have some other code in place that inserts blank
lines prior to doing the paste. Is there a way that I can just insert
the copied cells???

Thank you so much in advance for your help!

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,290
Default Paste cells from one workbook to another

The copy and paste are written as one line.
If you make two lines out of it, a line continuation character
is required. Like this:

....copy _
Destination:=...
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware



wrote in message
Hi all,
I'm new to VBA programming and I have what should be a simple question
for you experts!
Basically, I have 2 workbooks and I want to copy a range of cells from
Workbook A and paste them in Workbook B. I am getting a 'subscript out
of range' error when I try to pase and I cannot figure out why. Below
you will find the code that I am using:

Set wbDest = ActiveWorkbook
Set wbSource = Workbooks.Open(cdbBrowse.Filename)
wbSource.Worksheets("Sheet1").Range("A9:E13").Copy
Destination:=wbDest.Worksheets("Sheet1").Range("A9 :E13")

I know the problem is something with the Destination because if I just
do the Copy statement with no destination, I get no error.

Also, right now I have some other code in place that inserts blank
lines prior to doing the paste. Is there a way that I can just insert
the copied cells???

Thank you so much in advance for your help!

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Paste cells from one workbook to another

Hi, thank you for your response. In my code I do have it all in one
line. It just appears to be 2 lines because of the way the line breaks
in the post!

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,290
Default Paste cells from one workbook to another

Are you sure that there is a sheet named "Sheet1" in the destination workbook?
If it is there, check to make sure that a space hasn't been added to the sheet name.
--
Jim Cone
San Francisco, USA
http://www.officeletter.com/blink/specialsort.html



wrote in message
Hi, thank you for your response. In my code I do have it all in one
line. It just appears to be 2 lines because of the way the line breaks
in the post!

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
How to copy a range of cells and paste into a new workbook in differentcolumns Mas[_4_] Excel Discussion (Misc queries) 3 August 16th 11 02:57 PM
'External links' in formulas when the user paste cells to other workbook? tskogstrom Excel Programming 3 October 7th 06 04:11 AM
I cannot paste from one workbook to another. Copy works, paste do. JimmyMc Excel Discussion (Misc queries) 1 June 10th 05 03:54 PM
Need a macro to copy a range in one workbook and paste into another workbook Paul Excel Programming 8 July 1st 04 07:42 AM
Copy a range of cells in an unopened workbook and paste it to the current workbook topstar Excel Programming 3 June 24th 04 12:50 PM


All times are GMT +1. The time now is 08:16 PM.

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"