+ Reply to Thread
Results 1 to 13 of 13

Trying to copy an entire worksheet into a new worksheet in Excel 2010

  1. #1
    Registered User
    Join Date
    06-19-2005
    Posts
    49

    Trying to copy an entire worksheet into a new worksheet in Excel 2010

    Not sure why this is not working below. I simply want to copy the worksheet "Send" from an open workbook and create another separate workbook with the copy with a date identifier in the name. I am getting a Run-time error '91' on the last line "Object variable or With block variable not set" and it is creating another worksheet in my workbook (Send2) in error. Cannot figure this out. Can anyone help me? Thx.

    Please Login or Register  to view this content.

  2. #2
    Forum Contributor
    Join Date
    01-03-2013
    Location
    Aberdeen, Scotland
    MS-Off Ver
    Excel 2007
    Posts
    163

    Re: Trying to copy an entire worksheet into a new worksheet in Excel 2010

    You have to assign a workbook object to variable wb1 by using Set statement.

  3. #3
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,456

    Re: Trying to copy an entire worksheet into a new worksheet in Excel 2010

    And, if you want to copy the sheet to a new workbook, it would be just:

    Please Login or Register  to view this content.

    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  4. #4
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,456

    Re: Trying to copy an entire worksheet into a new worksheet in Excel 2010

    Oh, and then, probably ActiveWorkbook.SaveAs

  5. #5
    Registered User
    Join Date
    06-19-2005
    Posts
    49

    Re: Trying to copy an entire worksheet into a new worksheet in Excel 2010

    How would you assign a workbook object to variable wb1 by using Set statement?

  6. #6
    Registered User
    Join Date
    06-19-2005
    Posts
    49

    Re: Trying to copy an entire worksheet into a new worksheet in Excel 2010

    Quote Originally Posted by TMS View Post
    Oh, and then, probably ActiveWorkbook.SaveAs
    But then it would save the whole workbook wouldn't it? I just want to save what is on the sheet.

  7. #7
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,456

    Re: Trying to copy an entire worksheet into a new worksheet in Excel 2010

    No. If you copy a sheet without specifying the target location, it will create a new workbook with only that sheet in it. And the new workbook will become the active workbook. Hence you can save and name it.


    Regards, TMS

  8. #8
    Registered User
    Join Date
    06-19-2005
    Posts
    49

    Re: Trying to copy an entire worksheet into a new worksheet in Excel 2010

    Ok, what would the whole code look like?

  9. #9
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,456

    Re: Trying to copy an entire worksheet into a new worksheet in Excel 2010

    Something like:

    Please Login or Register  to view this content.

    Regards, TMS

  10. #10
    Registered User
    Join Date
    06-19-2005
    Posts
    49

    Re: Trying to copy an entire worksheet into a new worksheet in Excel 2010

    Ok, thx. Here is what happens. I am running Microsoft Excel 2010 64 Bit, Windows 7 64 Bit.

    First, I get the following notification in a box titled "Microsoft Excel - Compatibility Checker":

    "The following features in this workbook are not supported by earlier versions of Excel. These features may be lost or degraded when you save this workbook in the currently selected file format. Click Continue to save the workbook anyway. To keep all of your features, click Cancel and then save the file in one of the new file formats."

    And then below in the box under a title called Summary I get:

    "This workbook contains data in cells outside of the row and column limit of the selected file format. Data beyond 256 (IV) columns by 65,536 rows will not be saved." . . . and it goes on to say other things.

    This is interesting to me because the test sheet that i am 'sending' is only 5 records by 14 fields. There are other parts of the spreadsheet that have over 750K records though. But why would it give me this box since I am not sending that sheet. I think the problem is, it is not saving the file as an Excel 2010 file.

    At the bottom of the box it asks me if I want to continue.

    I say yes, and then the program freezes and does not save the file. It only saves a place holder "7BDA8900" (or some other random number) roughly the size of what the saved worksheet would be. I have to kill the program and start it up again to retrieve excel.

    thx for your continued help.

  11. #11
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,456

    Re: Trying to copy an entire worksheet into a new worksheet in Excel 2010

    I don't know. I don't have that version of Excel. However, I just used your code ... the only thing I changed was the output folder, for obvious reasons.

    I have just recorded and tweaked a macro to copy a sheet to a new workbook and save it as macro enabled.

    Please Login or Register  to view this content.

    I don't have anything to test so I'm afraid you're on your own.

    Regards, TMS

  12. #12
    Registered User
    Join Date
    06-19-2005
    Posts
    49

    Re: Trying to copy an entire worksheet into a new worksheet in Excel 2010


  13. #13
    Registered User
    Join Date
    06-19-2005
    Posts
    49

    Re: Trying to copy an entire worksheet into a new worksheet in Excel 2010

    I think what is needed is a separate instance of Excel.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Excel 2010 Macro to copy worksheet, update formula and rename worksheet
    By madmak0203 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-29-2012, 09:18 PM
  2. [SOLVED] Copy entire row in one worksheet, paste in next blank row in another worksheet
    By dev111ski in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-20-2012, 01:02 PM
  3. Drop Down List to Copy Entire Contents of Worksheet into Master Worksheet
    By mrmartin in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 07-14-2011, 10:54 PM
  4. Copy entire worksheet to another worksheet
    By friscokid in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-14-2008, 07:26 PM
  5. How do I copy an entire worksheet to another instance of excel?
    By Alan in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 06-30-2005, 02:05 AM

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