+ Reply to Thread
Results 1 to 7 of 7

Error - You cannot use this command on a protected sheet - after macro runs successfully

  1. #1
    Registered User
    Join Date
    07-27-2018
    Location
    Newcastle
    MS-Off Ver
    2013
    Posts
    20

    Unhappy Error - You cannot use this command on a protected sheet - after macro runs successfully

    Hello there,

    I've setup a simple macro to copy the last sheet in a workbook, copy to the end, rename the sheet, update some formulas and clear some values back to zero. It works great, however, when I try to move to another sheet, after the macro has been run, I get the error above. I don't know if its because I'm just using a blanket protect command which protects everything? Do I need to be more specific? But, saying that, after several times dismissing the message, it doesnt return until the macro is run again.


    Please Login or Register  to view this content.
    Last edited by mjmitch; 07-27-2018 at 09:12 AM.

  2. #2
    Forum Expert JLGWhiz's Avatar
    Join Date
    02-20-2011
    Location
    Florida, USA
    MS-Off Ver
    Windows 10, Excel 2013
    Posts
    2,070

    Re: Error - You cannot use this command on a protected sheet - after macro runs successful

    See if this re-write of the code will work better.

    Please Login or Register  to view this content.
    Any code provided by me should be tested on a copy or a mock up of your original data before applying it to the original. Some events in VBA cannot be reversed with the undo facility in Excel. If your original post is satisfied, please mark the thread as "Solved". To upload a file, see the banner at top of this page.
    Just when I think I am smart, I learn something new!

  3. #3
    Registered User
    Join Date
    07-27-2018
    Location
    Newcastle
    MS-Off Ver
    2013
    Posts
    20

    Re: Error - You cannot use this command on a protected sheet - after macro runs successful

    Thanks for the reply JLGWhiz, much appreciated, however the code got a runtime error 1004, 'Select method of range class failed'. Any ideas

  4. #4
    Forum Expert JLGWhiz's Avatar
    Join Date
    02-20-2011
    Location
    Florida, USA
    MS-Off Ver
    Windows 10, Excel 2013
    Posts
    2,070

    Re: Error - You cannot use this command on a protected sheet - after macro runs successful

    Quote Originally Posted by mjmitch View Post
    Thanks for the reply JLGWhiz, much appreciated, however the code got a runtime error 1004, 'Select method of range class failed'. Any ideas
    Please Login or Register  to view this content.
    You didn't really need that line anyhow. try this modified version.

  5. #5
    Registered User
    Join Date
    07-27-2018
    Location
    Newcastle
    MS-Off Ver
    2013
    Posts
    20

    Re: Error - You cannot use this command on a protected sheet - after macro runs successful

    Thanks JLGWhiz. I think the code is trying to update the sheet that was copied and not the new sheet, I presume that's because the sheet selection is not changed to the new sheet after its copied, prior to the .range selections. I've tried adding [sheets(sheets.count).Select] after the copying and renaming of the sheet, but get an error. How can I get the code to run the value updates and find/replace on the new sheet?

  6. #6
    Registered User
    Join Date
    07-27-2018
    Location
    Newcastle
    MS-Off Ver
    2013
    Posts
    20

    Re: Error - You cannot use this command on a protected sheet - after macro runs successful

    Update: the code is renaming the copied sheet, not the new sheet

  7. #7
    Forum Expert JLGWhiz's Avatar
    Join Date
    02-20-2011
    Location
    Florida, USA
    MS-Off Ver
    Windows 10, Excel 2013
    Posts
    2,070

    Re: Error - You cannot use this command on a protected sheet - after macro runs successful

    Quote Originally Posted by mjmitch View Post
    Update: the code is renaming the copied sheet, not the new sheet
    Somehow, I got off on the wrong tangent from the original problem. The ActiveSheet.Protect command only sets the currently active sheet. So whatever is triggering the error message would be related to something in that active sheet. If you click the debug button when you get the message, it should show a highlighted line of code that can give you a clue to where the fault is. In the meantime, abandon the revised code that I suggested because it was targeting the wrong issue.

+ 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. Error message needed if text is red before a command button runs it's coding
    By kjb123 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 12-27-2017, 06:20 PM
  2. [SOLVED] Macro error for protected sheet
    By bryden2008 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-13-2017, 04:17 PM
  3. Macro runs successfully but displays "Out of Memory" error at end
    By nobodyukno in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-22-2017, 10:37 AM
  4. Run Time Error 1004 - You cannot use this command on a protected sheet
    By frogboy in forum Excel Programming / VBA / Macros
    Replies: 17
    Last Post: 12-11-2012, 07:59 AM
  5. [SOLVED] Macro Error when Sheet is Protected
    By Johnny in forum Excel General
    Replies: 6
    Last Post: 07-28-2006, 02:45 PM
  6. [SOLVED] macro on protected sheet-error
    By michaelberrier in forum Excel General
    Replies: 6
    Last Post: 06-11-2006, 01:35 PM
  7. [SOLVED] Error Handling - On Error GoTo doesn't trap error successfully
    By David in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 02-16-2006, 02:10 PM

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