+ Reply to Thread
Results 1 to 24 of 24

Save As worksheet based on cell value on another sheet

  1. #1
    Forum Contributor
    Join Date
    12-11-2009
    Location
    Toronto
    MS-Off Ver
    Excel 2010
    Posts
    517

    Save As worksheet based on cell value on another sheet

    Getting error on this line and not sure why. Can someone please help

    error message = "Subscript out of Range"

    Please Login or Register  to view this content.
    Last edited by biznez; 05-06-2015 at 12:27 PM.

  2. #2
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Save As worksheet based on cell value on another sheet

    biznez,

    Hi again, are you SURE there is a sheet called Input? And if so... are you sure the active workbook at that time is the one that has the worksheet by that name?
    Please help by:

    Marking threads as closed once your issue is resolved. How? The Thread Tools at the top
    Any reputation (*) points appreciated. Not just by me, but by all those helping, so if you found someone's input useful, please take a second to click the * at the bottom left to let them know

    There are 10 kinds of people in this world... those who understand binary, and those who don't.

  3. #3
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Save As worksheet based on cell value on another sheet

    Hi

    Are you sure the sheet tab name is "Input" and not say "Inputs"?

    Incidentally you should avoid using the sheet tab name in a macro. One day someone will change the tab name and you'll be stuffed.
    Instead use the VBA sheet CodeName
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  4. #4
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Save As worksheet based on cell value on another sheet

    Do you have Worksheet named "Input"? Double check for spaces in the name (ie " Input", "Input ", " Input ")

  5. #5
    Registered User
    Join Date
    03-18-2015
    Location
    Wisconsin, USA
    MS-Off Ver
    2010
    Posts
    14

    Re: Save As worksheet based on cell value on another sheet

    Either you don't have a worksheet named "Input", or you'll have to activate "Input" prior to looking for a value in it.

  6. #6
    Forum Contributor
    Join Date
    12-11-2009
    Location
    Toronto
    MS-Off Ver
    Excel 2010
    Posts
    517

    Re: Save As worksheet based on cell value on another sheet

    Quote Originally Posted by Arkadi View Post
    biznez,

    Hi again, are you SURE there is a sheet called Input? And if so... are you sure the active workbook at that time is the one that has the worksheet by that name?
    Hi Arkadi, yes its called "Input". Sheets "Temp" and "Input" are in the same workbook

  7. #7
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Save As worksheet based on cell value on another sheet

    you could try changing that line to:
    Please Login or Register  to view this content.
    * Assuming that the code is in the workbook with the sheet "Input"

  8. #8
    Forum Contributor
    Join Date
    12-11-2009
    Location
    Toronto
    MS-Off Ver
    Excel 2010
    Posts
    517

    Re: Save As worksheet based on cell value on another sheet

    Quote Originally Posted by Arkadi View Post
    you could try changing that line to:
    Please Login or Register  to view this content.
    * Assuming that the code is in the workbook with the sheet "Input"
    Thanks Arkadi, that worked great. How can i hardcode columns A:L to the worksheet it saves?

  9. #9
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Save As worksheet based on cell value on another sheet

    biznez, glad that worked out. What do you mean hardcode A:L? are those columns the result of formulas and you only want the resulting values, instead of keeping formulas?

  10. #10
    Forum Contributor
    Join Date
    12-11-2009
    Location
    Toronto
    MS-Off Ver
    Excel 2010
    Posts
    517

    Re: Save As worksheet based on cell value on another sheet

    Quote Originally Posted by Arkadi View Post
    biznez, glad that worked out. What do you mean hardcode A:L? are those columns the result of formulas and you only want the resulting values, instead of keeping formulas?
    yes Arkadi

  11. #11
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Save As worksheet based on cell value on another sheet

    biznez, I don't see you pasting any data anywhere in the code you pasted... is there more to the macro, and if so can you provide the rest of the code?

  12. #12
    Forum Contributor
    Join Date
    12-11-2009
    Location
    Toronto
    MS-Off Ver
    Excel 2010
    Posts
    517

    Re: Save As worksheet based on cell value on another sheet

    Quote Originally Posted by Arkadi View Post
    biznez, I don't see you pasting any data anywhere in the code you pasted... is there more to the macro, and if so can you provide the rest of the code?
    Actually there are formulas in sheet Temp and when its saved, it also saves the formulas. just want the values to be saved

  13. #13
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Save As worksheet based on cell value on another sheet

    before saving...

    Please Login or Register  to view this content.

  14. #14
    Forum Contributor
    Join Date
    12-11-2009
    Location
    Toronto
    MS-Off Ver
    Excel 2010
    Posts
    517

    Re: Save As worksheet based on cell value on another sheet

    Quote Originally Posted by Arkadi View Post
    before saving...

    Please Login or Register  to view this content.
    This hardcoded the file Temp with the code but not the save as file

  15. #15
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Save As worksheet based on cell value on another sheet

    did you put the code in BEFORE the saveas code? if so, then try putting it earlier... before the .copy code.

  16. #16
    Forum Contributor
    Join Date
    12-11-2009
    Location
    Toronto
    MS-Off Ver
    Excel 2010
    Posts
    517

    Re: Save As worksheet based on cell value on another sheet

    Quote Originally Posted by Arkadi View Post
    did you put the code in BEFORE the saveas code? if so, then try putting it earlier... before the .copy code.
    this code did save the file hard-coded, however it also removed the formulas in Temp. Any way around this? so the Temp file does not get hard coded but only the saved file does? this is the code i have so far. Thanks again Arkadi

    HTML Code: 

  17. #17
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Save As worksheet based on cell value on another sheet

    ok... lets see...


    Please Login or Register  to view this content.

  18. #18
    Forum Contributor
    Join Date
    12-11-2009
    Location
    Toronto
    MS-Off Ver
    Excel 2010
    Posts
    517

    Re: Save As worksheet based on cell value on another sheet

    Thanks Arkadi...u the man!
    one more issue if you dont mind. The file that is saved has trailing blank spaces. I want those to be removed. For example file shows as Billy Wilson .xls

  19. #19
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Save As worksheet based on cell value on another sheet

    Please Login or Register  to view this content.

  20. #20
    Forum Contributor
    Join Date
    12-11-2009
    Location
    Toronto
    MS-Off Ver
    Excel 2010
    Posts
    517

    Re: Save As worksheet based on cell value on another sheet

    Quote Originally Posted by Arkadi View Post
    Please Login or Register  to view this content.
    Thank you so much Arkadi. I would Rep you again if i could

  21. #21
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Save As worksheet based on cell value on another sheet

    As general advice, keep in mind that when you open or saveas, your active workbook changes. As such it is usually best to be specific about workbook as well as sheet references when working with multiple books, ActiveWorkbook, ThisWorkbook(which is the one containing the macro that is running at the time) are very useful. Or dim variables as workbook and then set them so you can reference them in your code.

  22. #22
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Save As worksheet based on cell value on another sheet

    Quote Originally Posted by biznez View Post
    Thank you so much Arkadi. I would Rep you again if i could
    Actually you can.... you can rep any post by someone... I have given quite a bit of rep to the same person, sometimes even multiple times on the same thread (not same post though). In fact I would think you have given rep to a few people multiple times, since you get lots of help sometimes from people like John. I once thanked you for rep in a message and asked you don't duplicate... but the duplicate thing was about posting the same problem twice... multiple rep is encouraged if you are helped multiple times by same person. We all help because we can and we like to, rep is purely optional, but always appreciated, it is our only "reward".
    Last edited by Arkadi; 05-06-2015 at 12:44 PM.

  23. #23
    Forum Contributor
    Join Date
    12-11-2009
    Location
    Toronto
    MS-Off Ver
    Excel 2010
    Posts
    517

    Re: Save As worksheet based on cell value on another sheet

    Quote Originally Posted by Arkadi View Post
    As general advice, keep in mind that when you open or saveas, your active workbook changes. As such it is usually best to be specific about workbook as well as sheet references when working with multiple books, ActiveWorkbook, ThisWorkbook(which is the one containing the macro that is running at the time) are very useful. Or dim variables as workbook and then set them so you can reference them in your code.
    Thanks for the advice

  24. #24
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Save As worksheet based on cell value on another sheet

    No problem! Thanks for the rep, and thanks for being so good about marking your threads as Solved, makes our life much easier

+ 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. [SOLVED] Save Each Worksheet as a PDF File and Name each File Based on a Cell Value in each Sheet
    By hamidxa in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-16-2016, 09:36 AM
  2. [SOLVED] Save sheet to new sheet and name it based on date on first sheet cell
    By dwheggen1 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-28-2015, 12:25 PM
  3. [SOLVED] Save sheet based on cell value
    By abjac in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-08-2013, 11:28 PM
  4. Save Worksheet Based on Cell Value
    By Mooseman60 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-20-2011, 05:22 PM
  5. Macros to save worksheet based on cell reference
    By JimmiOO in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 02-13-2009, 01:29 PM

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