Results 1 to 2 of 2

Error 1004: Unable to set the Locked property of the Range class

Threaded View

  1. #1
    Registered User
    Join Date
    05-12-2021
    Location
    México
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (16.0.13530.20054)
    Posts
    17

    Unhappy Error 1004: Unable to set the Locked property of the Range class

    Dear Experts:

    Hope this post finds you well!

    I'm trying to lock an entire Worksheet except for some cells depending on the content of a specific cell on another sheet.

    This lock/unlock is evaluated when the sheet to be locked (Context) is activated.

    Private Sub Worksheet_Activate()
    
        If ThisWorkbook.Worksheets("Options").Range("B480").Value = "1" Then
            ActiveSheet.Unprotect Password:="123"
            ThisWorkbook.Worksheets("Context").Range("F32:F33,L37:L38,T37:T38,V6:V7,V9,F30,T35,N35,F35,N32,Z32,N30,S30,B3:AI305,F35,N32:N33,Z32:Z33,N30,S30,Z30").Locked = True
            ActiveSheet.Protect Password:="123", UserInterfaceOnly:=True
        Else
            ActiveSheet.Unprotect Password:="123"
            ThisWorkbook.Worksheets("Context").Range("F32:F33,L37:L38,T37:T38,V6:V7,V9,F30,T35,N35,F35,N32,Z32,N30,S30,B3:AI305,F35,N32:N33,Z32:Z33,N30,S30,Z30").Locked = False
            ActiveSheet.Protect Password:="123", UserInterfaceOnly:=True
        End If
    
    End Sub
    The range to be locked/unlocked includes merged cells and single cells. Initially, the sheet is locked with the password "123" and allows editing only on the range indicated.

    The thing is that I'm getting this error:

    Error.png
    Debug.png

    Could you please advice?

    Thanks in advance! Have a great day!
    Last edited by Magmarinita; 06-17-2021 at 12:03 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Locking WS getting Run-time error 1004 Unable to set locked property of the range class
    By thecdnmole in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 12-20-2020, 12:22 AM
  2. [SOLVED] Error 1004 Unable to set the hidden property of the range class
    By Tholmq in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 07-17-2018, 03:39 PM
  3. Run-time error '1004'; Unable to set the Locked property of the Range class
    By haridevadiga in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-29-2015, 07:30 AM
  4. [SOLVED] Run-time error '1004' Unable to set the Locked Property of the Range Class
    By medakiva in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-09-2013, 09:13 AM
  5. Error 1004: Unable to Set Hidden property of the range class...
    By jaysakle in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 10-03-2013, 02:51 AM
  6. Run-time error '1004' Unable to set the Locked Property of the Range Class
    By Jerums in forum Excel Programming / VBA / Macros
    Replies: 20
    Last Post: 03-04-2013, 04:22 PM
  7. Error 1004 Unable to set the Hidden Property of the Range Class
    By nld in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-08-2007, 10:56 AM

Tags for this Thread

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