+ Reply to Thread
Results 1 to 14 of 14

Copy/Paste, between open workbooks,syntax

  1. #1
    Forum Expert JapanDave's Avatar
    Join Date
    06-10-2008
    Location
    The grid, I got in!
    MS-Off Ver
    Excel 2010/13
    Posts
    1,696

    Copy/Paste, between open workbooks,syntax

    I am having a little trouble figuring out the syntax for coping and pasting between different workbooks. Can anyone show me how to write the syntax for this?

    This is what I have so far, it is not finished so obviously won't work.

    Please Login or Register  to view this content.
    Last edited by JapanDave; 08-31-2011 at 09:12 AM.

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Copy/Paste, between open workbooks,syntax

    Is this macro going to reside IN the data workbook?
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Copy/Paste, between open workbooks,syntax

    I would expect something along the lines of:

    Please Login or Register  to view this content.

  4. #4
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Copy/Paste, between open workbooks,syntax

    But if only values are your concern, this will suffice:

    Please Login or Register  to view this content.



  5. #5
    Forum Expert JapanDave's Avatar
    Join Date
    06-10-2008
    Location
    The grid, I got in!
    MS-Off Ver
    Excel 2010/13
    Posts
    1,696

    Re: Copy/Paste, between open workbooks,syntax

    Thanks Jerry and SNB, that helps me immensly in understanding this syntax.

    Jerry, it is actually the other way around, "Newbook" was just a reference for me to make thing easier to understand when writing the code. The Data workbook is the book I receive each month with new data in it. Newbook is where the code will reside.

    I modified your code Jerry to select a range, is this the best way to do it? or is there a better way to select a group of cells?
    Please Login or Register  to view this content.
    Also , as an after thought , there is a possibility in the future that the Data I am receiving will have a dynamic number of rows.
    I was made this code, but it is not working. I get an error?

    Please Login or Register  to view this content.
    Last edited by JapanDave; 08-30-2011 at 09:29 AM.

  6. #6
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Copy/Paste, between open workbooks,syntax

    In that case:

    Please Login or Register  to view this content.

  7. #7
    Forum Expert JapanDave's Avatar
    Join Date
    06-10-2008
    Location
    The grid, I got in!
    MS-Off Ver
    Excel 2010/13
    Posts
    1,696

    Re: Copy/Paste, between open workbooks,syntax

    Thanks SNB, but I can't seem to get this code to work, it runs through with no errors, so I am not sure what is wrong. I will check my workbook names and worksheet names to make sure I have not made any typos.

  8. #8
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Copy/Paste, between open workbooks,syntax

    Hi JapanDave. Be sure to indicate in new lines of code which sheet it is to apply to.

    Please Login or Register  to view this content.

  9. #9
    Forum Expert JapanDave's Avatar
    Join Date
    06-10-2008
    Location
    The grid, I got in!
    MS-Off Ver
    Excel 2010/13
    Posts
    1,696

    Re: Copy/Paste, between open workbooks,syntax

    Thanks Jerry for the explanation.

    Going back to your earlier code,
    Please Login or Register  to view this content.
    I can't seem to manipulate this code to work in the "NewBook" workbook, it will reside in the "NewBook" , not the "Data" workbook. Sorry for the confusion.

  10. #10
    Forum Expert JapanDave's Avatar
    Join Date
    06-10-2008
    Location
    The grid, I got in!
    MS-Off Ver
    Excel 2010/13
    Posts
    1,696

    Re: Copy/Paste, between open workbooks,syntax

    Hey SNB,

    Could you help me understand this line?
    Please Login or Register  to view this content.
    At the moment it is selecting only Row1 ,Column1. How would you adjust the code to select multiple columns and start the copy in Row3?

    Sorry for all the questions guys, but you don't know how much this is helping me understand different aspects of VBA.

  11. #11
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Copy/Paste, between open workbooks,syntax

    Please Login or Register  to view this content.

  12. #12
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Copy/Paste, between open workbooks,syntax

    If you make sure column A doesn't contain empty cells, the code will do it's job.
    Since you didn't provide a sample worksheet it's rather guessing....

    but if you want to 'copy' the whole worksheet to cells(3,3) ("C3")

    Please Login or Register  to view this content.
    Last edited by snb; 08-31-2011 at 03:52 AM.

  13. #13
    Forum Expert JapanDave's Avatar
    Join Date
    06-10-2008
    Location
    The grid, I got in!
    MS-Off Ver
    Excel 2010/13
    Posts
    1,696

    Re: Copy/Paste, between open workbooks,syntax

    @Jerry, Thanks for that, I was leaving out the "xls" part and that is where I was going wrong.

    @SNB, I can post an example for you to take a look at, but it is at work. I will try and get it uploaded tomorrow. BTW, the first column has no blank cells and it does select the whole first column which has about 3000 rows, but I wondering how I would be able to have select columns out to say the 20th column on the source sheet, assuming that there are no blanks cells in any of the columns?

  14. #14
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Copy/Paste, between open workbooks,syntax

    To 'copy' the 20th column in sheet 'Record' in workbook 'Data' to the 3rd column in sheet 'Report' in workbook 'Newbook':

    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1