run-time error 424; object required error

dsheard2015

Board Regular
Joined
May 10, 2016
Messages
134
Hello,

I am receiving a run-time error 424; object required message. The error appeared after I added the code lines in red.

Basically, whenever the worksheet opens, I'm trying to lock any cell within that range that is not blank. Any help is greatly appreciated!

Thanks,
Dave

Code:
Private Sub Worksheet_Activate()


Dim rLockable As Range
Dim cl As Range
    
ActiveSheet.Unprotect Password:=Sheets("Worksheet Names").Range("O11").Value


    If Range("H1").Value = Sheets("User List").Range("A56").Value Then


        Range("A8:A53, A64:A109, A120:A165, A176:A221, A232:A277, A288:A333, A344:A389, A400:A445, A456:A501, A512:A557, C8:C53, C64:C109, C120:C165, C176:C221, C232:C277, C288:C333, C344:C389, C400:C445, C456:C501, C512:C557").Locked = True
        Range("B8:B53, B64:B109, B120:B165, B176:B221, B232:B277, B288:B333, B344:B389, B400:B445, B456:B501, B512:B557").Locked = False


        Else


            If Range("H1") = "" Then


                Range("A8:A53, A64:A109, A120:A165, A176:A221, A232:A277, A288:A333, A344:A389, A400:A445, A456:A501, A512:A557, C8:C53, C64:C109, C120:C165, C176:C221, C232:C277, C288:C333, C344:C389, C400:C445, C456:C501, C512:C557").Locked = False
                Range("B8:B53, B64:B109, B120:B165, B176:B221, B232:B277, B288:B333, B344:B389, B400:B445, B456:B501, B512:B557").Locked = True


            End If
    End If


[COLOR=#ff0000]Set rLockable = Range("A8:C53, A64:C109, A120:C165, A176:C221, A232:C277, A288:C333, A344:C389, A400:C445, A456:C501, A512:C557")[/COLOR]
[COLOR=#ff0000]
[/COLOR]
[COLOR=#ff0000]    For Each cl In Target[/COLOR]
[COLOR=#ff0000]        [/COLOR]
[COLOR=#ff0000]        If cl.Value = "" Then[/COLOR]
[COLOR=#ff0000]            cl.Locked = False[/COLOR]
[COLOR=#ff0000]            [/COLOR]
[COLOR=#ff0000]            Else[/COLOR]
[COLOR=#ff0000]            [/COLOR]
[COLOR=#ff0000]            cl.Locked = True[/COLOR]
[COLOR=#ff0000]
[/COLOR]
[COLOR=#ff0000]        End If[/COLOR]
[COLOR=#ff0000]        [/COLOR]
[COLOR=#ff0000]    Next cl[/COLOR]


ActiveSheet.Protect Password:=Sheets("Worksheet Names").Range("O11").Value


End Sub




Private Sub Worksheet_Change(ByVal Target As Range)


    Dim rLockable As Range
    Dim cl As Range
    
    Set rLockable = Range("A8:C53, A64:C109, A120:C165, A176:C221, A232:C277, A288:C333, A344:C389, A400:C445, A456:C501, A512:C557")
    
    'If target is within the range then do nothing
    If Intersect(rLockable, Target) Is Nothing Then Exit Sub
    ActiveSheet.Unprotect Password:=Sheets("Worksheet Names").Range("O11").Value
    For Each cl In Target
        If cl.Value <> "" Then
            check = MsgBox("Is this entry correct? This cell cannot be changed after entering a value.", vbYesNo, "Cell Lock Notification")
            If check = vbYes Then
                cl.Locked = True
            Else
                ActiveCell.Select
            End If
        End If
    Next cl
ActiveSheet.Protect Password:=Sheets("Worksheet Names").Range("O11").Value
End Sub
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
You don't appear to have a Target in that sub...

Code:
For Each cl In Target
did you mean
Code:
For Each cl In rLockable
 
Upvote 0
Hello Mark858,

I am away from my computer right now but I will make that change once I get back to the office and let you know.

Thank you!

Dave
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,337
Members
452,637
Latest member
Ezio2866

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top