Solved

Macro to show which cells are formatted "locked"

Posted on 2011-03-08
6
449 Views
Last Modified: 2012-05-11
I'd like to see which cells are locked and which are unlocked on a sheet containing a mixture of locked and unlocked cells.

Can anyone help with a macros that shows all cells that are locked or unlocked, eg by shading the cells different colours?

Thanks
0
Comment
Question by:StuartOrd
6 Comments
 
LVL 59

Accepted Solution

by:
Saurabh Singh Teotia earned 350 total points
Comment Utility

You can use this code to do what you are looking for...

Saurabh...
Sub checkdata()
    Dim rng As Range, cell As Range

    ActiveSheet.Unprotect Password:="password"  '<----Give your sheet password

    Set rng = Range("A1:N100")           '<----  Define your range you want to check

    For Each cell In rng
        If cell.Locked = True Then
            cell.Interior.ColorIndex = 3         '<----- Cell color if the cell is locked you can change the number as per you..
        Else
            cell.Interior.ColorIndex = 6     '<----- Cell color if the cell is locked you can change the number as per you..
        End If
    Next cell

    ActiveSheet.Protect Password:="password"   '<--- Give your sheet password.



End Sub

Open in new window

0
 
LVL 20

Expert Comment

by:pari123
Comment Utility
Try this -

Please let me know if this works.

this is for office 2007.

- ardhendu
Option Explicit
Sub Macro1()
    Dim cel As Range
    For Each cel In Selection
        If cel.Locked = False Then
            With cel.Interior
                .Pattern = xlSolid
                .PatternColorIndex = xlAutomatic
                .ThemeColor = xlThemeColorLight2
                .TintAndShade = 0.599993896298105
                .PatternTintAndShade = 0
            End With
        Else
            With cel.Interior
                .Pattern = xlSolid
                .PatternColorIndex = xlAutomatic
                .ThemeColor = xlThemeColorAccent2
                .TintAndShade = 0.599993896298105
                .PatternTintAndShade = 0
            End With
        End If
    Next
End Sub

Open in new window

0
 
LVL 6

Expert Comment

by:royhsiao
Comment Utility
Nice job Pari123.
If you add cells.select below Dim Cel as range in Pari 123's code like  the following:
====
Dim cel As Range
    Cells.Select
====
It will check all cells. When you find the cells just click Esc to stop the macros.
0
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 

Author Comment

by:StuartOrd
Comment Utility
saurabh726,
That worked fine! Thanks.

pari123
I'm using 2003, so maybe that's why it failed at:
.Pattern = xlSolid
0
 
LVL 50

Assisted Solution

by:Dave Brett
Dave Brett earned 150 total points
Comment Utility
You may find this article useful,  
A fast method for determining the unlocked cell range http://www.experts-exchange.com/A_2769.html

It provides a very fast technique for returning the unlocked cell range without looping

You could use it in conjunction with
Adding a "Subtract Range" method alongside Union & Intersect  Article   http://www.experts-exchange.com/A_2974.html
to return the locked cell range (ie subtract the unlocked range from the usedrange)

Cheers

Dave
0
 

Author Comment

by:StuartOrd
Comment Utility
brettdj,
Yes I can see that adding some features of this new article to saurabh726's code makes a good solution. I realised i needed to copy my sheet as many sheets have colour formatting that I didn't want to lose, and this method makes an automatic copy and doesn't recolour the sheets, so i can pick and choose a suitable hybrid.
Thanks all, excellent help as usual
Stuart
0

Featured Post

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

Join & Write a Comment

What is a Form List Box? (skip if you know this) The forms List Box is the alternative to the ActiveX list box. If you are using excel 2007, you first make sure you have a developer tab (click the Orb)->"Excel Options"->Popular->"Show Developer tab…
Improved? Move/Copy Add-in Replacement - How to avoid the annoying, “A formula or sheet you want to move or copy contains the name XXX, which already exists on the destination worksheet.” David Miller (dlmille)  It was one of those days… I wa…
The viewer will learn how to simulate a series of coin tosses with the rand() function and learn how to make these “tosses” depend on a predetermined probability. Flipping Coins in Excel: Enter =RAND() into cell A2: Recalculate the random variable…
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…

728 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

10 Experts available now in Live!

Get 1:1 Help Now