Solved

Password Protect Individual Columns in Excel w/ VBA

Posted on 2013-11-22
11
1,914 Views
Last Modified: 2013-11-22
Is there a way to password protect active cell individual columns with VBA?
0
Comment
Question by:mattfmiller
[X]
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
  • 6
  • 3
  • 2
11 Comments
 
LVL 4

Expert Comment

by:yuppydu
ID: 39669340
No, as far as I know you cannot password protect one cell or one column
0
 
LVL 47

Expert Comment

by:Martin Liss
ID: 39669355
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

0
 
LVL 47

Expert Comment

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

Open in new window

0
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
LVL 4

Expert Comment

by:yuppydu
ID: 39669391
Martin that locks it, but can you password protect it as Matt asked? I do not know of way for doing that
0
 
LVL 47

Expert Comment

by:Martin Liss
ID: 39669413
    With ActiveSheet
        .Columns("C:C").Locked = True
        .Protect Password:="My password"
    End With

Open in new window

0
 
LVL 1

Author Comment

by:mattfmiller
ID: 39669439
Is there a way to password protect a relative reference?
0
 
LVL 47

Expert Comment

by:Martin Liss
ID: 39669672
Is there a way to password protect a relative reference?
Please give me an example of what you mean.
0
 
LVL 1

Author Comment

by:mattfmiller
ID: 39669689
For example

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

ActiveCell.offset(1,0).select



Loop
0
 
LVL 47

Accepted Solution

by:
Martin Liss earned 500 total points
ID: 39669719
I'm not sure what you mean here Do while ActiveCell.value = "" = false but this should work for the rest

    With ActiveSheet
        If ActiveCell.Interior.Color = vbRed Then
            .Columns(ActiveCell.Column).Locked = True
            .Protect Password:="My password"
        End If
    End With

Open in new window

0
 
LVL 1

Author Comment

by:mattfmiller
ID: 39670252
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)
0
 
LVL 47

Expert Comment

by:Martin Liss
ID: 39670287
You're welcome and I'm glad I was able to help.

Marty - MVP 2009 to 2013
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.

710 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