+ Reply to Thread
Results 1 to 6 of 6

Error: You cannot use this command on protected sheet

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    02-13-2016
    Location
    MUMBAI
    MS-Off Ver
    Microsoft 365
    Posts
    180

    Error: You cannot use this command on protected sheet

    Sub Protect_All_Formula_cells()
    
    Application.ScreenUpdating = False
    
    For i = 1 To Sheets.Count
    
        With Sheets(i)
          .Unprotect Password:="abcd"
        
            With .Cells
             .Locked = False
             .FormulaHidden = False
            End With
            
             Cells.SpecialCells(xlCellTypeFormulas, 23).Select 'error line: you cannot use this command on protected sheet
             Selection.Locked = True
             Selection.FormulaHidden = False
            
    Range("A1").Select
            
        .Protect Password:="abcd", DrawingObjects:=True, Contents:=True, Scenarios:=True, _
        AllowFormattingCells:=True, AllowFormattingColumns:=True, AllowFormattingRows:=True, _
        AllowInsertingHyperlinks:=True, AllowFiltering:=True
        
        End With
            
      Next i
      
    Application.ScreenUpdating = True
    
    End Sub
    I have tried unprotecting the sheet with the code but still getting the error.

    Solution??

  2. #2
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow


    The codeline where error occurs is not the one unprotected but the active sheet as you forgot the dot before Cells statement ‼

  3. #3
    Forum Contributor
    Join Date
    02-13-2016
    Location
    MUMBAI
    MS-Off Ver
    Microsoft 365
    Posts
    180

    Re: Error: You cannot use this command on protected sheet

    After inserting dot before cells statement, it gives error that select method of range class failed.

  4. #4
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,789

    Re: Error: You cannot use this command on protected sheet

    You cannot select cells on an inactive sheet.
    Try
    With .Cells.SpecialCells(xlCellTypeFormulas, 23)
       .Locked = True
       .FormulaHidden = False
    End With

  5. #5
    Forum Contributor
    Join Date
    02-13-2016
    Location
    MUMBAI
    MS-Off Ver
    Microsoft 365
    Posts
    180

    Re: Error: You cannot use this command on protected sheet

    Solved!! Thanks a lot!

  6. #6
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,789

    Re: Error: You cannot use this command on protected sheet

    You're welcome & thanks for the feedback

+ 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. Add Row Command Button on Protected Sheet?
    By msjesbrown93 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-16-2019, 01:21 PM
  2. Replies: 6
    Last Post: 07-31-2018, 08:14 AM
  3. Replies: 3
    Last Post: 01-29-2016, 03:57 PM
  4. You cannot use this command on a protected sheet
    By rsinha in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-10-2015, 03:32 PM
  5. [SOLVED] Error 400 when sheet is protected
    By Master Foo in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-03-2013, 04:07 PM
  6. 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
  7. [SOLVED] Runtime Error using Command Button when Worksheet is Protected
    By HangMan in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-08-2012, 09:17 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