Tryng to lock with offset

Ciccio86

New Member
Joined
Feb 3, 2023
Messages
27
Office Version
  1. 365
Platform
  1. Windows
Hi, im tryng to lock a range with offset.

VBA Code:
Sub DCHK()
Application.Calculation = xlCalculationManual
Application.ScreenUpdating = False
Application.DisplayStatusBar = False
Application.EnableEvents = False

Dim chk As OLEObject

For Each chk In ActiveSheet.OLEObjects
    If TypeName(chk.Object) = "CheckBox" And chk.Object.Value = False Then
        If chk.TopLeftCell.Offset(0, 0).Value = LP Then
            If chk.TopLeftCell.Offset(0, 1).Locked = False Then
                chk.TopLeftCell.Offset(0, 1).Locked = True
            End If
            If chk.TopLeftCell.Offset(0, -2).Locked = False Then
                chk.TopLeftCell.Offset(0, -2).Locked = True
            End If
        'chk.Visible = False
        End If
    End If
Next
  
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
Application.DisplayStatusBar = True
Application.EnableEvents = True
End Sub

I have error "Unable to set Locked property of Range Class error" 1004 on this code
VBA Code:
chk.TopLeftCell.Offset(0, -2).Locked = True
The cell is a merged cell i tried also to put (0, -1) but i have the same error
LP is a variable
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
If your sheet is protected, you'll need to first unprotect it at the beginning of your code, and then again protect it at the end of it.
 
Upvote 0

Forum statistics

Threads
1,224,820
Messages
6,181,159
Members
453,021
Latest member
Justyna P

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