+ Reply to Thread
Results 1 to 7 of 7

How to warn that one cell, within a range, is locked?

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    08-04-2005
    Location
    Madrid, Spain
    MS-Off Ver
    2010
    Posts
    241

    How to warn that one cell, within a range, is locked?

    In a macro I need for a message to appear warning that cells are protected.
    I know of this code, when only one cell is involved:

    If Range("A1").Locked Then
    MsgBox "The cell is protected"
    or
    If ActiveCell.Locked Then
    But this time I have a range of cells to be written on, say A5 to D9.
    What would the “If...” code be for the message to appear in case only one cell, any one, or any several cells within that range, are locked?

    Thanks for any help.
    ACA
    Last edited by aca; 04-04-2014 at 05:51 PM.

  2. #2
    Forum Expert
    Join Date
    11-28-2012
    Location
    Guatemala
    MS-Off Ver
    Excel 2010
    Posts
    2,394

    Re: How to warn that one cell, within a range, is locked?

    by the same logic...
    If Range("A5:d9").Locked Then
    MsgBox "The range A5:D9 cell is protected"

  3. #3
    Forum Contributor
    Join Date
    08-04-2005
    Location
    Madrid, Spain
    MS-Off Ver
    2010
    Posts
    241

    Re: How to warn that one cell, within a range, is locked?

    Thanks, rcm; i've tried that and the message does not appear. I guess that will do when the whole range is locked.
    But what if only one or any two cells are locked, not the whole range?
    ACA

  4. #4
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: How to warn that one cell, within a range, is locked?

    If Range("A5:d9").Locked Then
    MsgBox "The range A5:D9 cell is protected"
    I believe the above code will work if the whole range is locked but not if only a few cell within that range are. Try this:

    Sub Identify_Locked_Cells()
    Dim myRange As Range, rCell As Range
    Dim strRange As String
    
    Set myRange = Range("A5:D9")
    
    For Each rCell In myRange
        If rCell.Locked = True Then
            If strRange = "" Then
                strRange = rCell.Address
            Else
                strRange = strRange & ", " & rCell.Address
            End If
        End If
    Next rCell
    
    MsgBox ("The following cells are locked: " & strRange)
    
    End Sub

  5. #5
    Forum Expert
    Join Date
    11-28-2012
    Location
    Guatemala
    MS-Off Ver
    Excel 2010
    Posts
    2,394

    Re: How to warn that one cell, within a range, is locked?

    how about the change macro that would test only the specified range?

  6. #6
    Forum Contributor
    Join Date
    08-04-2005
    Location
    Madrid, Spain
    MS-Off Ver
    2010
    Posts
    241

    Re: How to warn that one cell, within a range, is locked?

    Thank you, stnkynts. That works all right. I didn't think it was so complex though; but it's all right. Thanks
    ACA

  7. #7
    Forum Contributor
    Join Date
    08-04-2005
    Location
    Madrid, Spain
    MS-Off Ver
    2010
    Posts
    241

    Re: How to warn that one cell, within a range, is locked?

    Thanks. rcm. but I am not sure what the "change macro" is.
    Anyway, somebody gave me an answer. Bye.
    ACA

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Pop up to warn against blank cell in a table
    By sambashir in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-16-2013, 07:31 AM
  2. [SOLVED] Help!! How to warn users that a cell is blank
    By EM1987 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-08-2013, 08:46 AM
  3. Replies: 2
    Last Post: 03-07-2012, 09:42 AM
  4. Placing a number based on the rage of another cell
    By The Inquistor in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 03-31-2008, 04:38 PM
  5. Warn when a cell value has changed
    By LesLdh in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 02-16-2005, 02:33 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1