+ Reply to Thread
Results 1 to 18 of 18

Run Time Error 1004 - You cannot use this command on a protected sheet

  1. #1
    Registered User
    Join Date
    12-21-2011
    Location
    Aus
    MS-Off Ver
    Excel 2010
    Posts
    62

    Run Time Error 1004 - You cannot use this command on a protected sheet

    Hi I have a spreadsheet with various code and I am trying to lock certain parts of the spreadsheet to ensure nothing gets changed by accident. However when i drop down a menu (part of a VLOOKUP function) it come up with the error in the subject line and point the 'debug' as below:
    Runtime Error 1004.JPG

  2. #2
    Forum Contributor
    Join Date
    09-05-2012
    Location
    It's more fun in the Philippines :D
    MS-Off Ver
    Excel 2007
    Posts
    209

    Re: Run Time Error 1004 - You cannot use this command on a protected sheet

    @frogboy

    based on the error description, your sheet is currently protected.
    try to add to add this code before the "set" code and on the last line consecutively,
    sheet1.unprotect password:="your password"
    sheet1.protect password:="your password"

    Regards,
    thisisgerald
    Don't forget to mark your thread as [SOLVED].

  3. #3
    Registered User
    Join Date
    12-21-2011
    Location
    Aus
    MS-Off Ver
    Excel 2010
    Posts
    62

    Re: Run Time Error 1004 - You cannot use this command on a protected sheet

    Hi thisisgerald, I have tried this but it comes up with the following error and points the debug at the "password"
    (which is my password)
    "Compile Error - Invalid outside Procedure"

  4. #4
    Registered User
    Join Date
    12-21-2011
    Location
    Aus
    MS-Off Ver
    Excel 2010
    Posts
    62

    Re: Run Time Error 1004 - You cannot use this command on a protected sheet

    Hi thisisgerald, I have tried this but it comes up with the following error and points the debug at the "password"
    (which is my password)
    "Compile Error - Invalid outside Procedure"

  5. #5
    Forum Contributor
    Join Date
    09-05-2012
    Location
    It's more fun in the Philippines :D
    MS-Off Ver
    Excel 2007
    Posts
    209

    Re: Run Time Error 1004 - You cannot use this command on a protected sheet

    can you attach your sample workbook instead?

  6. #6
    Registered User
    Join Date
    12-21-2011
    Location
    Aus
    MS-Off Ver
    Excel 2010
    Posts
    62

    Re: Run Time Error 1004 - You cannot use this command on a protected sheet

    unfortunately it contains a lot of sensitive data, and would take too much time to remove and then repost.

  7. #7
    Registered User
    Join Date
    12-21-2011
    Location
    Aus
    MS-Off Ver
    Excel 2010
    Posts
    62

    Re: Run Time Error 1004 - You cannot use this command on a protected sheet

    instead I have attached the full VBA script (albeit with a few things edited), hope this helps?
    Please Login or Register  to view this content.

  8. #8
    Forum Contributor
    Join Date
    09-05-2012
    Location
    It's more fun in the Philippines :D
    MS-Off Ver
    Excel 2007
    Posts
    209

    Re: Run Time Error 1004 - You cannot use this command on a protected sheet

    @frogboy,

    disregard my first suggestion, i found out that it cannot unprotect the sheet since the code is on worksheet change.

    kindly try this one, add these:

    Please Login or Register  to view this content.
    Then close your file then open it again.

    Your new code will be like this:

    Please Login or Register  to view this content.
    Last edited by thisisgerald; 12-03-2012 at 07:25 AM.

  9. #9
    Registered User
    Join Date
    12-21-2011
    Location
    Aus
    MS-Off Ver
    Excel 2010
    Posts
    62

    Re: Run Time Error 1004 - You cannot use this command on a protected sheet

    Unfortunately it hasnt made any difference and comes up with the same error message. cheers

  10. #10
    Forum Contributor
    Join Date
    09-05-2012
    Location
    It's more fun in the Philippines :D
    MS-Off Ver
    Excel 2007
    Posts
    209

    Re: Run Time Error 1004 - You cannot use this command on a protected sheet

    on what part you are encountering error? have you tried the code below on post #8?

  11. #11
    Registered User
    Join Date
    12-21-2011
    Location
    Aus
    MS-Off Ver
    Excel 2010
    Posts
    62

    Re: Run Time Error 1004 - You cannot use this command on a protected sheet

    yes, tried the code and comes up with the original error message. I have added the code, saved and closed the spreadsheet and then reopened it without any difference. cheers

  12. #12
    Registered User
    Join Date
    12-21-2011
    Location
    Aus
    MS-Off Ver
    Excel 2010
    Posts
    62

    Re: Run Time Error 1004 - You cannot use this command on a protected sheet

    Bump .... anyone??

  13. #13
    Forum Contributor
    Join Date
    09-05-2012
    Location
    It's more fun in the Philippines :D
    MS-Off Ver
    Excel 2007
    Posts
    209

    Re: Run Time Error 1004 - You cannot use this command on a protected sheet

    @frogboy

    which part are you having run-time error?

    this code should be under "ThisWorkbook".

    Please Login or Register  to view this content.
    while this one is in your active sheet:

    Please Login or Register  to view this content.

  14. #14
    Registered User
    Join Date
    12-21-2011
    Location
    Aus
    MS-Off Ver
    Excel 2010
    Posts
    62

    Re: Run Time Error 1004 - You cannot use this command on a protected sheet

    excellent, that worked. Apologies for being a newb!!
    Thanks

  15. #15
    Registered User
    Join Date
    12-21-2011
    Location
    Aus
    MS-Off Ver
    Excel 2010
    Posts
    62

    Re: Run Time Error 1004 - You cannot use this command on a protected sheet

    ... in fact sorry it didnt work. If I protect the sheet and save and close and then re-open it the pages is not protected. It appears it loses its protection on closing? Probably something else I have missed? Please advise? cheers

  16. #16
    Registered User
    Join Date
    12-21-2011
    Location
    Aus
    MS-Off Ver
    Excel 2010
    Posts
    62

    Re: Run Time Error 1004 - You cannot use this command on a protected sheet

    ... not an expert but reading the code it says to protect on closing and unprotect on opening. However I want to stop people being able to mess with formulas when they are in the spreadsheet so this appears to be defeating the object of originally protecing the sheet?

  17. #17
    Forum Contributor
    Join Date
    09-05-2012
    Location
    It's more fun in the Philippines :D
    MS-Off Ver
    Excel 2007
    Posts
    209

    Re: Run Time Error 1004 - You cannot use this command on a protected sheet

    @frogboy,

    maybe you can start recording macros on protecting worksheet.
    I'm not sure if the macro unprotected then protect the worksheet, the default options will be applied.

    regards,
    thisisgerald

  18. #18
    Registered User
    Join Date
    12-21-2011
    Location
    Aus
    MS-Off Ver
    Excel 2010
    Posts
    62

    Re: Run Time Error 1004 - You cannot use this command on a protected sheet

    sorry I dont understand what you mean?
    Are there any other thoughts on this?

+ 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