+ Reply to Thread
Results 1 to 12 of 12

HELP - Code to Copy/Format/Save/Print Worksheet Based on Cell Values

  1. #1
    Registered User
    Join Date
    03-21-2011
    Location
    Australia
    MS-Off Ver
    Excel 2007
    Posts
    58

    HELP - Code to Copy/Format/Save/Print Worksheet Based on Cell Values

    Hi,

    I currently have a code that copies a worksheet in WB1, creates a new WB and renames the newly created file then saves it based on the value of two cells within the new WB.

    The issue I have been facing is that once the values from the two cells combined become longer then 31 characters, the VB coding bugs out and returns an error message saying Run-time Error '1004'.

    The coding I am using atm is:

    Please Login or Register  to view this content.
    Can anyone please advise how i can get around this bug and allow me to rename and save the new WB based on cells having values over 31 characters?

    The two key cells i am trying to reference is G7 & B13.

    Thank you.
    Last edited by larzep; 03-06-2012 at 01:42 AM.

  2. #2
    Forum Expert Mordred's Avatar
    Join Date
    07-06-2010
    Location
    Winnipeg, Canada
    MS-Off Ver
    2007, 2010
    Posts
    2,787

    Re: Copy Worksheet to New Workbook then save and rename based on cell values

    What cell contains the name of the new workbook and what cell contains the new worksheet?
    If you're happy with someone's help, click that little star at the bottom left of their post to give them Reps.

    ---Keep on Coding in the Free World---

  3. #3
    Registered User
    Join Date
    03-21-2011
    Location
    Australia
    MS-Off Ver
    Excel 2007
    Posts
    58

    Re: Copy Worksheet to New Workbook then save and rename based on cell values

    The two cells that contain the value to rename the sheet and workbook are - G7 (Quote number) and B13 (Company name Pty Ltd)

  4. #4
    Registered User
    Join Date
    03-21-2011
    Location
    Australia
    MS-Off Ver
    Excel 2007
    Posts
    58

    Re: Copy Worksheet to New Workbook then save and rename based on cell values

    can anyone help me with the issue of the macro bugging out when the combined characters of the two cell is more then 31 characters?
    Last edited by larzep; 03-05-2012 at 09:59 PM.

  5. #5
    Registered User
    Join Date
    03-21-2011
    Location
    Australia
    MS-Off Ver
    Excel 2007
    Posts
    58

    Re: Copy Worksheet to New Workbook then save and rename based on cell values

    Just bumping the post to get more feedback and help.

  6. #6
    Forum Expert DGagnon's Avatar
    Join Date
    02-23-2012
    Location
    Ontario, Canada
    MS-Off Ver
    Excel 2003, 2007
    Posts
    1,645

    Re: Copy Worksheet to New Workbook then save and rename based on cell values

    could you attach a sample copy of the workbook as well?
    If you liked my solution, please click on the Star -- to add to my reputation

    If your issue as been resolved, please clearly state so and mark the thread as [SOLVED] using the thread tools just above the first post.

  7. #7
    Registered User
    Join Date
    03-21-2011
    Location
    Australia
    MS-Off Ver
    Excel 2007
    Posts
    58

    Re: Copy Worksheet to New Workbook then save and rename based on cell values

    Yes i have attached a copy of the spreadsheet.
    Attached Files Attached Files

  8. #8
    Registered User
    Join Date
    03-21-2011
    Location
    Australia
    MS-Off Ver
    Excel 2007
    Posts
    58

    Re: HELP - Code to Copy/Format/Save/Print Worksheet Based on Cell Values

    Can anyone help?

  9. #9
    Forum Expert DGagnon's Avatar
    Join Date
    02-23-2012
    Location
    Ontario, Canada
    MS-Off Ver
    Excel 2003, 2007
    Posts
    1,645

    Re: HELP - Code to Copy/Format/Save/Print Worksheet Based on Cell Values

    what if you take only the first 20 characters of the company name?

    Please Login or Register  to view this content.
    Last edited by DGagnon; 03-06-2012 at 07:59 PM. Reason: pasted wrong code section

  10. #10
    Registered User
    Join Date
    03-21-2011
    Location
    Australia
    MS-Off Ver
    Excel 2007
    Posts
    58

    Re: HELP - Code to Copy/Format/Save/Print Worksheet Based on Cell Values

    Thanks dgagnon for the reply.

    I would love to make it simpler, but the thing is when i save the file, i will have another macro to PDF it then send an email to the client with their company name on the file. I would prefer it to keep the full company name along with the quote number.

    Sorry to be a pain but is there anyway to bypass that 31 character save limit?

  11. #11
    Forum Expert DGagnon's Avatar
    Join Date
    02-23-2012
    Location
    Ontario, Canada
    MS-Off Ver
    Excel 2003, 2007
    Posts
    1,645

    Re: HELP - Code to Copy/Format/Save/Print Worksheet Based on Cell Values

    the limit is only for the Sheet name, not for the actual file name, so you can still save the filename as long as you want, but the sheet name needs to be less than 31 char in length.

  12. #12
    Registered User
    Join Date
    03-21-2011
    Location
    Australia
    MS-Off Ver
    Excel 2007
    Posts
    58

    Re: HELP - Code to Copy/Format/Save/Print Worksheet Based on Cell Values

    thanks for that. if you put it that way, i can simply modify the names to allocate for the sheet. Will test out the macro again with the limit of 20 characters.

+ 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