vba code or alternative method to lock one column in worksheet

Posted on 2014-03-19
Last Modified: 2014-03-20
Hi  Experts Excel 2007

How would I lock/protect column dw and leave remaining column unprotected.
Question by:route217
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 51

Expert Comment

ID: 39939577

pls try

    ActiveSheet.Unprotect ' EDITED
    Cells.Locked = False
    Columns("DW:DW").EntireColumn.Locked = True
    ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True

Open in new window


Author Comment

ID: 39939699

I am assuming that I add this to the worksheet...module.
LVL 51

Accepted Solution

Rgonzo1971 earned 250 total points
ID: 39939711
Run it once from a normal module
Sub Macro
    Cells.Locked = False
    Columns("DW:DW").EntireColumn.Locked = True
    ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
End Sub

Open in new window

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.


Expert Comment

ID: 39939719
Rgonzo1971's solution is good.

Named range will help you when your sheet dynamic. when you add new column or delete a column before the particular column your required column name will change but named range remain same we can access the column using the named range.

for ex:- create named range in column "DW" as "MyColumn"

ThisWorkbook.Names("MyColumn").RefersToRange.EntireColumn.Locked = True
LVL 47

Assisted Solution

by:Martin Liss
Martin Liss earned 250 total points
ID: 39939955
Or you can do something as simple as this which moves the cursor to column dv.

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Column = 127 Then
    Cells(Target.Row, Target.Column - 1).Select
End If
End Sub

Open in new window


Author Comment

ID: 39940264
Thanks for the feedback experts testing.

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
Excel can be a tricky bit of software to get your head around. Whilst you’ll be able to eventually get to grips with the basic understanding of how to get by, there are a few Excel tips that not everybody will even know about let alone know how to d…
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

732 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question