Link to home
Start Free TrialLog in
Avatar of Matt Miller
Matt MillerFlag for United States of America

asked on

Password Protect Individual Columns in Excel w/ VBA

Is there a way to password protect active cell individual columns with VBA?
Avatar of yuppydu
yuppydu
Flag of Italy image

No, as far as I know you cannot password protect one cell or one column
Avatar of Martin Liss
Sure you can. The sheet must be protected but if you do this but by default only things that are locked will be effected, so then do this.

    Columns("C:C").Select
    Selection.Locked = True

Open in new window

Actually there's no need to Select, so...
    Columns("C:C").Locked = True

Open in new window

Martin that locks it, but can you password protect it as Matt asked? I do not know of way for doing that
    With ActiveSheet
        .Columns("C:C").Locked = True
        .Protect Password:="My password"
    End With

Open in new window

Avatar of Matt Miller

ASKER

Is there a way to password protect a relative reference?
Is there a way to password protect a relative reference?
Please give me an example of what you mean.
For example

Do while ActiveCell.value = "" = false
If Activecell.interior.color = red then
Protect column
End if

ActiveCell.offset(1,0).select



Loop
ASKER CERTIFIED SOLUTION
Avatar of Martin Liss
Martin Liss
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thx.  I ended up going with with

ActiveCell.Columns("A:A").EntireColumn.Locked = True

then closing the loop with the ActiveSheet.protect.

The password I will incorporate into my macro (Didn't know you could do that)
You're welcome and I'm glad I was able to help.

Marty - MVP 2009 to 2013