+ Reply to Thread
Results 1 to 4 of 4

Run Time Error 9 Subscript out of Range

  1. #1
    Registered User
    Join Date
    01-18-2010
    Location
    CT
    MS-Off Ver
    Excel 2003
    Posts
    17

    Run Time Error 9 Subscript out of Range

    Can anyone tell me why this macro (which I use to sort rows) is generating an error message?

    Sub sortstores()
    Sheets("OER Dashboard Report").Unprotect Password:="Grimmer"
    Range("C11:Y89").Sort Key1:=Range("F1"), _
    Order1:=xlDescending, Header:=xlGuess, _
    OrderCustom:=1, MatchCase:=False, _
    Orientation:=xlTopToBottom, _
    DataOption1:=xlSortTextAsNumbers
    Sheets("OER Dashboard Report").Protect Password:="Grimmer"
    End Sub

  2. #2
    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: Run Time Error 9 Subscript out of Range

    Hi,

    Your sort key is outside the sort range. Try F11 instead.

    HTH
    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.

  3. #3
    Registered User
    Join Date
    01-18-2010
    Location
    CT
    MS-Off Ver
    Excel 2003
    Posts
    17

    Re: Run Time Error 9 Subscript out of Range

    Richard,

    The error still seems to be occuring. When I remove the unlock/lock aspect of the macro, it works fine however it creates an error when the password aspects are present. Any idea why this may be happening?

    I basically need the above macro to, when executed, unlock the sheet, run the sort macro, then re-lock the sheet. The sheet's name is OER Dashboard Report and the password is Grimmer

  4. #4
    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: Run Time Error 9 Subscript out of Range

    Hi,

    If the OER Dashboard Report isn't the active sheet at the time you invoke the sort then you will encounter an error. Try a fully defined sort range. i.e.


    Please Login or Register  to view this content.
    or perhaps more elegantly with a WITH statement

    Please Login or Register  to view this content.
    HTH

+ 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