+ Reply to Thread
Results 1 to 9 of 9

Using string to saveas getting subscript out of range error

  1. #1
    Registered User
    Join Date
    09-12-2013
    Location
    NW MN
    MS-Off Ver
    Excel 2010
    Posts
    17

    Using string to saveas getting subscript out of range error

    I am trying to set things as strings and saving using those variables, but I can't seem to get it to work. There is no way to use a dynamic variable either with a cell range containing data, as this is formatted exactly how it needs to be imported. So, I had to manually set the if...elseif, and the length of the path and everything going on I seem to have missed something. I am toying around with the second elseif, as 370 is the first worksheet in the workbook, so that is different than the rest. Any fresh eyes out there able to catch something I am doing wrong besides having gross looking filepaths?

    Please Login or Register  to view this content.

  2. #2
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: Using string to saveas getting subscript out of range error

    Hi, pbarry,

    giving a Format inside a String wonīt be really helpfull as the command canīt be reckognized by VBA. Maybe try
    Please Login or Register  to view this content.
    as an example for the first occurrance of the Format.

    Ciao,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

  3. #3
    Registered User
    Join Date
    09-12-2013
    Location
    NW MN
    MS-Off Ver
    Excel 2010
    Posts
    17

    Re: Using string to saveas getting subscript out of range error

    HaHoBe, thanks for the advice. I will try it out here in a little bit. Makes sense to separate things within the string. I'll let you know how it works!

  4. #4
    Registered User
    Join Date
    09-12-2013
    Location
    NW MN
    MS-Off Ver
    Excel 2010
    Posts
    17

    Re: Using string to saveas getting subscript out of range error

    It worked for the first 2 of 6 saves, then I got a "method 'saveas' of object'_workbook failed". Not sure why it worked the first 2 workbooks, but gets hung up here?

  5. #5
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: Using string to saveas getting subscript out of range error

    Hi, pbarry,

    what is Company370_ in the third part: a variable or a string?

    Maybe try
    Please Login or Register  to view this content.
    Ciao,
    Holger

  6. #6
    Registered User
    Join Date
    09-12-2013
    Location
    NW MN
    MS-Off Ver
    Excel 2010
    Posts
    17

    Re: Using string to saveas getting subscript out of range error

    It gets through Company 370 and 380 fine, but struggles here:

    Please Login or Register  to view this content.
    looking at this, here's the error. wow for stupid, I thought I changed them all.
    Please Login or Register  to view this content.
    The Companies are sorted prior to the IF...ELSE IF statement so it will look from lowest to highest.

  7. #7
    Registered User
    Join Date
    09-12-2013
    Location
    NW MN
    MS-Off Ver
    Excel 2010
    Posts
    17

    Re: Using string to saveas getting subscript out of range error

    Ok, I must be all confused here...thsi is the code that I have in the macro. I must have pulled it from somewhere else with the ^^ reply, sorry for the confusion.

    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    09-12-2013
    Location
    NW MN
    MS-Off Ver
    Excel 2010
    Posts
    17

    Re: Using string to saveas getting subscript out of range error

    Hahobe, I tried your modification by bringing the tail end of that filename into the declared variable and it is still getting hung up on the 3 set of criteria. Kind of frustrating when it works for the first two, then fails the next three then works on the last one? As far as my eyes can see, the paths are correct after checking it a dozen times and it doesn't seem to want to work. I will try restarting my computer and see if that solves it.

  9. #9
    Registered User
    Join Date
    09-12-2013
    Location
    NW MN
    MS-Off Ver
    Excel 2010
    Posts
    17

    Re: Using string to saveas getting subscript out of range error

    Funny thing, on half of the paths, the verbiage is this "2. Formatted MRP Forecast", and then the other half like this, "2. Formatted MRP". Inconsistent data ruined a few of my hours, sorry for being a pest on here!

+ 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. Runtime Error - Subscript out of Range / Object Error
    By JHRice in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-04-2012, 05:14 PM
  2. Defining Array - Runtime error 9, Subscript out of range error
    By MaartenW in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 02-03-2012, 07:32 AM
  3. Run-time error '9': Subscript out of range -- on .SaveAs
    By DJBittner in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-27-2011, 05:21 PM
  4. Subscript out of range error - save copy error
    By bg18461 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-13-2006, 11:53 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