+ Reply to Thread
Results 1 to 8 of 8

Run-time error '9': Subscript out of range (With Statement)

  1. #1
    Registered User
    Join Date
    08-26-2013
    Location
    Seattle
    MS-Off Ver
    Excel 2013
    Posts
    5

    Run-time error '9': Subscript out of range (With Statement)

    Hey All,

    I am trying to run a macro that will update a sheet in the workbook and post it in another location. I did not build this macro and have limited work with macros compared to the person who built it. Running the macro gives me a Run-time error '9' error within a With statement. Any advice would be much appreciated.

    Please Login or Register  to view this content.
    The directories this code references have not changed since the last running of the macro, so I do not believe that would be the issue.

    Thanks again!
    Last edited by mariocubed; 12-10-2013 at 08:40 PM.

  2. #2
    Forum Expert Solus Rankin's Avatar
    Join Date
    05-24-2013
    Location
    Hollywood, CA
    MS-Off Ver
    Win7 Office 2010 VS Express 2012
    Posts
    2,655

    Re: Run-time error '9': Subscript out of range (With Statement)

    What line does the error occur on?
    Thanks,
    Solus


    Please remember the following:

    1. Use [code] code tags [/code]. It keeps posts clean, easy-to-read, and maintains VBA formatting.
    Highlight the code in your post and press the # button in the toolbar.
    2. Show appreciation to those who have helped you by clicking below their posts.
    3. If you are happy with a solution to your problem, mark the thread as [SOLVED] using the tools at the top.

    "Slow is smooth, smooth is fast."

  3. #3
    Registered User
    Join Date
    08-26-2013
    Location
    Seattle
    MS-Off Ver
    Excel 2013
    Posts
    5

    Re: Run-time error '9': Subscript out of range (With Statement)

    The error occurs within the first the With statement after the Bye.

    With Workbooks(strReportFileName).Sheets(strReportSheetName)
    .Range("E6") = "All-up"
    .Range("E7") = "All-up"
    .Range("E8") = "All-up"
    End With
    Workbooks(strReportFileName).Sheets(strPostingSheetName).Select
    Range("A2").Select

  4. #4
    Forum Expert Solus Rankin's Avatar
    Join Date
    05-24-2013
    Location
    Hollywood, CA
    MS-Off Ver
    Win7 Office 2010 VS Express 2012
    Posts
    2,655

    Re: Run-time error '9': Subscript out of range (With Statement)

    are you sure strReportFileName and strReportSheetName are what you are expecting?

    try debug.print strReportFileName & " " & strReportSheetName right before your With Workbooks line and see what value the variable holds. Is the workbook by that name open?

  5. #5
    Forum Contributor
    Join Date
    03-14-2013
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    491

    Re: Run-time error '9': Subscript out of range (With Statement)

    try activating the workbook/sheet name, then do the with statement

  6. #6
    Forum Expert Solus Rankin's Avatar
    Join Date
    05-24-2013
    Location
    Hollywood, CA
    MS-Off Ver
    Win7 Office 2010 VS Express 2012
    Posts
    2,655

    Re: Run-time error '9': Subscript out of range (With Statement)

    If the variables hold the expected value, since they are fully qualified there should be no need to activate them.

    I'm thinking there is probably a variable that doesn't hold the value you think it does. Is there anyway you can attach your workbook as an example (with code in place) so we can do some investigating?

  7. #7
    Registered User
    Join Date
    08-26-2013
    Location
    Seattle
    MS-Off Ver
    Excel 2013
    Posts
    5

    Re: Run-time error '9': Subscript out of range (With Statement)

    Here is a copy of the workbook with all internal data removed
    Attached Files Attached Files

  8. #8
    Forum Expert Solus Rankin's Avatar
    Join Date
    05-24-2013
    Location
    Hollywood, CA
    MS-Off Ver
    Win7 Office 2010 VS Express 2012
    Posts
    2,655

    Re: Run-time error '9': Subscript out of range (With Statement)

    The variable is not holding the correct information. I placed a message box here:
    Please Login or Register  to view this content.
    to show what information the variable held. If you run this it shows that strReportFileName hold the value:
    "Microsoft Excel - test%20report[1].xlsm [Re" Because of the added characters on the trailing end this is not a valid workbook name, therefore it will give you an out of range error.

+ 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] run-time error '9': Subscript out of range - WHY??
    By pastotnikr in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-31-2013, 03:31 PM
  2. Run-time error 9: Subscript out of Range
    By boesingen in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-14-2013, 09:41 AM
  3. Run time error 9 Subscript out of range
    By vijanand1279 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-28-2012, 03:30 PM
  4. Subscript out of range error when using nested if statement
    By bradshaw in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 08-30-2008, 11:39 AM
  5. Runtime Error - Subscript out of range despite On Error statement
    By DoctorG in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-28-2006, 11: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