Solved

Password Protect Individual Columns in Excel w/ VBA

Posted on 2013-11-22
11
1,826 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
ID: 39669340
No, as far as I know you cannot password protect one cell or one column
0
 
LVL 46

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 46

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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
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 46

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 46

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 46

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 46

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

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Basic Excel DataEntry for Dashboard analysis 3 27
Excel Spacing Anomaly 4 25
VLOOKUP 6 19
How best to represent data in Excel? 13 29
Workbook link problems after copying tabs to a new workbook? David Miller (dlmille) Intro Have you either copied sheets to a new workbook, and after having saved and opened that workbook, you find that there are links back to the original sou…
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 viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.

832 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