+ Reply to Thread
Results 1 to 5 of 5

how to copy/paste to new workbook several times....

  1. #1
    Registered User
    Join Date
    10-15-2008
    Location
    Sydney
    MS-Off Ver
    Excel 2007
    Posts
    93

    how to copy/paste to new workbook several times....

    Hi there

    I'm trying to create an "export" feature where certain data can be copied out to a new workbook.

    I want to copy out the following from the current workbook to a new one:
    Sheets("1TR").Range("C33:M999") to range("A1") in the new workbook
    and
    Sheets("1PL").Range("K33:K999") to range ("L1") in the new workbook.


    The problem I'm having is that it is not just one copy/paste exercise, but two, and I don't know how to reference the new workbook as it doesn't have a filename....


    Please see below sample code. Any idea how to carry out this procedure?

    Thanks
    Sunil


    Please Login or Register  to view this content.
    Last edited by sunilmulay; 06-16-2009 at 10:49 PM.

  2. #2
    Forum Contributor
    Join Date
    03-25-2008
    MS-Off Ver
    Excel, Outlook, Word 2007/2003
    Posts
    245

    Re: how to copy/paste to new workbook several times....

    Don't promise a thing, but you could try this. Use F8 when stepping through the coding to see what action is doing what. When you use excel 2007, you'll have to create extra references to the worksheets and the ranges (as I did for the workbooks).

    Please Login or Register  to view this content.
    Charlize

  3. #3
    Forum Expert
    Join Date
    01-03-2006
    Location
    Waikato, New Zealand
    MS-Off Ver
    2010 @ work & 2007 @ home
    Posts
    2,243

    Re: how to copy/paste to new workbook several times....

    hi Sunil,

    What happens when you step through the code line by line using the [F8] key?
    Do you get any error messages when the code stops, if so, what are they?

    I believe your error is 2 lines further down in the code where you state:
    Please Login or Register  to view this content.
    Here are some ideas for using object variables (edit: on posting, I see Charlize beat me to it ) rather than strings for identifying workbooks & also an alternative approach to paste special:
    (note the code is untested)
    Please Login or Register  to view this content.
    hth
    Rob
    Last edited by broro183; 06-15-2009 at 08:28 AM.
    Rob Brockett
    Kiwi in the UK
    Always learning & the best way to learn is to experience...

  4. #4
    Registered User
    Join Date
    10-15-2008
    Location
    Sydney
    MS-Off Ver
    Excel 2007
    Posts
    93

    Re: how to copy/paste to new workbook several times....

    Hi there...

    thanks very much for your replies.

    I went with your suggestions, and it works a treat. I'm having a problem now though with a different part of my "export" procedure...

    Please see attached sample workbook. if you run the Export Macro, see what happens.

    The new file created by the macro should have no blank rows....the following part of the code is deleting SOME of the blank rows but not all....any idea what is going on? I'm totally baffled!

    Thanks in advance!!

    Sunil


    Please Login or Register  to view this content.
    Attached Files Attached Files

  5. #5
    Forum Expert
    Join Date
    01-03-2006
    Location
    Waikato, New Zealand
    MS-Off Ver
    2010 @ work & 2007 @ home
    Posts
    2,243

    Re: how to copy/paste to new workbook several times....

    hi Sunil,

    Thanks for the feedback, as the original of this post is solved, can you please mark the thread as solved and then start your new question in a new thread?

    Rob

+ 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