Add code to lock some columns and some specific cells

fvisions

Board Regular
Joined
Jul 29, 2008
Messages
191
Office Version
  1. 365
Platform
  1. Windows
Is it possible to add to this line of code to also lock cells AD1:AK1? I tried adding separate lines of code but they don't seem to be working. Any advice?

VBA Code:
.Range("AL1").Value = "Locked Columns A:AC = UnLocked Columns AD:AK"
   Worksheets("CWS").Cells.EntireColumn.AutoFit
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
My boss has asked for a second criteria to lock the worksheet. I am looking for guidance on how to lock rows that have "Do Not Change" in column Y. So there are may locks here so I may be making a mess of this. First request was to hide and lock columns A:AC but have AD:AK available for the end user. second request is to lock the headers in AD1:AK1, The 3rd request is to lock any row with the "Do Not Change" located in column Y. This has been altered several times hopefully my boss has made up is mind and this is it. What is your advice. Do I need to re-write the hold thing?

The full code is below :

VBA Code:
Sub Hide_Cells()

Dim ws As Worksheet

With Worksheets("CWS")
.Range("B1").Value = "."
.Range("D1").Value = "."
.Range("H1").Value = "Current Equipment"
.Range("Q1").Value = "."
.Range("AD1").Value = "Pole ID #"
.Range("AE1").Value = "LED Watt Installed"
.Range("AF1").Value = "Install Date"
.Range("AG1").Value = "Contractor Notes"
.Range("AH1").Value = "CMP Field"
.Range("AI1").Value = "CMP Field"
.Range("AJ1").Value = "CMP Field"
.Range("AK1").Value = "CMP Field"
.Range("AL1").Value = "Locked Columns A:AC = UnLocked Columns AD:AK"
Worksheets("CWS").Cells.EntireColumn.AutoFit

With Worksheets("CWS").Range("AD1:AK1").Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.ThemeColor = xlThemeColorAccent4
.TintAndShade = 0.599993896298105
.PatternTintAndShade = 0

With Worksheets("CWS").Columns("AB:AD")
.ColumnWidth = 13
End With
With Worksheets("CWS").Columns("B:AC")
.Locked = True
.FormulaHidden = False
End With
With Worksheets("CWS").Columns("AD:AK")
.Locked = False
.FormulaHidden = False
Worksheets("CWS").Range("B:f,H:j, L:O, Q:T").EntireColumn.Hidden = True
End With
Worksheets("CWS").Protect Password:="12121212"
End With
End With

End Sub
 
Upvote 0

Forum statistics

Threads
1,215,059
Messages
6,122,917
Members
449,093
Latest member
dbomb1414

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