Solved

vba code or alternative method to lock one column in worksheet

Posted on 2014-03-19
6
3,958 Views
Last Modified: 2014-03-20
Hi  Experts Excel 2007

How would I lock/protect column dw and leave remaining column unprotected.
0
Comment
Question by:route217
6 Comments
 
LVL 50

Expert Comment

by:Rgonzo1971
ID: 39939577
Hi,

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

Regards
0
 

Author Comment

by:route217
ID: 39939699
Experts

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

Accepted Solution

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

Open in new window

Regards
0
Industry Leaders: 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!

 
LVL 4

Expert Comment

by:senthilkumarsb
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
0
 
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
    Beep
    Cells(Target.Row, Target.Column - 1).Select
End If
    
End Sub

Open in new window

0
 

Author Comment

by:route217
ID: 39940264
Thanks for the feedback experts testing.
0

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

This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
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…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

679 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