Solved

Password Protect Individual Columns in Excel w/ VBA

Posted on 2013-11-22
11
1,750 Views
Last Modified: 2013-11-22
Is there a way to password protect active cell individual columns with VBA?
0
Comment
Question by:mattfmiller
  • 6
  • 3
  • 2
11 Comments
 
LVL 4

Expert Comment

by:yuppydu
Comment Utility
No, as far as I know you cannot password protect one cell or one column
0
 
LVL 45

Expert Comment

by:Martin Liss
Comment Utility
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 45

Expert Comment

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

Open in new window

0
 
LVL 4

Expert Comment

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

Expert Comment

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

Open in new window

0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 1

Author Comment

by:mattfmiller
Comment Utility
Is there a way to password protect a relative reference?
0
 
LVL 45

Expert Comment

by:Martin Liss
Comment Utility
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
Comment Utility
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 45

Accepted Solution

by:
Martin Liss earned 500 total points
Comment Utility
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
Comment Utility
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 45

Expert Comment

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

Marty - MVP 2009 to 2013
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction While answering a recent question (http:/Q_27311462.html), I created an alternative function to the Excel Concatenate() function that you might find useful.  I tested several solutions and share the results in this article as well as t…
This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

743 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now