+ Reply to Thread
Results 1 to 9 of 9

Copy data from workbook, create new workbook, paste data to new worbook?

  1. #1
    Registered User
    Join Date
    11-09-2009
    Location
    Canada
    MS-Off Ver
    Excel 2007
    Posts
    52

    Copy data from workbook, create new workbook, paste data to new worbook?

    I am using a UserForm to run a sorting macro on whatever data is entered into the UserForm text box. I then want to create a new workbook (name is time and date), copy data (Columns A:G) from the original workbook and paste to the new workbook, then save and close the new workbook. The UserForm will then clear the text box and you can add more data (which will go into another new workbook).

    The only problem I am having is pasting the data between the two. Any ideas? I have made a comment in the code below where I think I need to add something.

    Thanks again!

    Please Login or Register  to view this content.

  2. #2
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: Copy data from workbook, create new workbook, paste data to new worbook?

    It appears to me that you already have your columns copied. See
    Please Login or Register  to view this content.
    btw you can just write this as Columns("A:G").Copy

    Not sure which workbook is the active one and/or which one you want to paste to but in the spot you indicated you could do something like:
    Please Login or Register  to view this content.
    If you need to paste it in the new workbook but its not you could say
    Please Login or Register  to view this content.
    Let me know if this works and makes sense for you.

  3. #3
    Registered User
    Join Date
    11-09-2009
    Location
    Canada
    MS-Off Ver
    Excel 2007
    Posts
    52

    Re: Copy data from workbook, create new workbook, paste data to new worbook?

    Thanks! Sorry about the delay in getting back here.

    I have tried both pieces of code you provided, but I am getting the following error:

    Run-time error '1004':

    PasteSpecial method of Range class failed
    And the Debug command in VBA highlights the following piece of code:

    Please Login or Register  to view this content.

    This the same issue I was having before when I was trying to paste to the new workbook.

    Thoughts?
    Last edited by mpkavanagh; 02-04-2011 at 12:58 PM.

  4. #4
    Registered User
    Join Date
    11-09-2009
    Location
    Canada
    MS-Off Ver
    Excel 2007
    Posts
    52

    Re: Copy data from workbook, create new workbook, paste data to new worbook?

    BUMP. Still having some issues (please see my last post).

  5. #5
    Registered User
    Join Date
    11-09-2009
    Location
    Canada
    MS-Off Ver
    Excel 2007
    Posts
    52

    Re: Copy data from workbook, create new workbook, paste data to new worbook?

    BUMP. Still looking.

  6. #6
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: Copy data from workbook, create new workbook, paste data to new worbook?

    do you have any other data on the sheet with the range to copy? Maybe you will go for this option:

    Please Login or Register  to view this content.
    This will move copy of the activesheet to a new workbook.

  7. #7
    Registered User
    Join Date
    11-09-2009
    Location
    Canada
    MS-Off Ver
    Excel 2007
    Posts
    52

    Re: Copy data from workbook, create new workbook, paste data to new worbook?

    I added the copy code but do I need to pair it with a paste command after I create the new workbook?

    Please Login or Register  to view this content.

  8. #8
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: Copy data from workbook, create new workbook, paste data to new worbook?

    it might be like this
    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    11-09-2009
    Location
    Canada
    MS-Off Ver
    Excel 2007
    Posts
    52

    Re: Copy data from workbook, create new workbook, paste data to new worbook?



    Thank you! It works great.

    One more side note, it seems that this code creates and saves a new workbook (which is what I want it to do), but it also opens a new Workbook every time (Book1, Book2, Book3, etc.) I run it. Is there any reason for this in my code?

    EDIT: I still can't access old posts to change it to SOLVED. Can I mode change this to SOLVED?

    EDITx2: I found the problem, ActiveSheet.Copy appeared twice in my code. *sigh* This one is done, thanks!
    Last edited by mpkavanagh; 02-16-2011 at 06:46 PM.

+ 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