Unable to lock columns...

exceluser90

New Member
Joined
Jun 1, 2011
Messages
15
Hey I am currently trying to lock columns in my sheet based on the number of items in a ListBox, yet the code does not appear to have any affect.
Code:
If lockbox.Value = True Then
        Main.Range(Main.Columns(1), Main.Columns(Quarters.ListCount + 1)).Locked = True
End If

It seems like such a simple line of code, yet it doesn't seem to work. The cells remain unlocked.
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Locking cells won't have any effect unless the sheet is protected. try like this

Code:
If lockbox.Value = True Then
    main.Unprotect
        main.Range(main.Columns(1), main.Columns(Quarters.ListCount + 1)).Locked = True
    main.Protect
End If
 
Upvote 0
Also, if I check the cells after, they are not even locked. Weirder still, if I run the code separately, it works...
 
Upvote 0

Forum statistics

Threads
1,224,538
Messages
6,179,412
Members
452,912
Latest member
alicemil

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