Results 1 to 4 of 4

Protect/Unprotect code causing out of range error in code

Threaded View

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

    Protect/Unprotect code causing out of range error in code

    Guys,

    I was hoping someone could me identify why this is happening. I have a macro code which sorts a defined set of rows based on a particular column. Likewise, there is a macro that unsorts them back to their original positions. Now the macros themselves work perfectly, however, the sheet needs to be protected before distribution. When I input the code to protect/unprotect the sheets before and after the macro has run, I get a subscript out of range error.

    The name of the sheet in question is OER Dashboard Report and the password is Grimmer

    Here is an example of one of the two macros that work perfectly:

    Sub sortstores()
    'Change first range as needed
    'Do not change Key1
    Range("C11:Y89").Sort Key1:=Range("F1"), _
    Order1:=xlDescending, Header:=xlGuess, _
    OrderCustom:=1, MatchCase:=False, _
    Orientation:=xlTopToBottom, _
    DataOption1:=xlSortTextAsNumbers
    End Sub



    The subscript out of range error occurs when I change the code to this:



    Sub sortstores()
    Sheets("OER Dashboard Report").Unprotect Password:="Grimmer"
    'Change first range as needed
    'Do not change Key1
    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



    Any ideas??
    Last edited by Petrolcb41; 12-02-2010 at 02:26 PM.

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