+ Reply to Thread
Results 1 to 5 of 5

Thread: Lock cell and grey out cells depending on cell

  1. #1
    Registered User
    Join Date
    01-03-2012
    Location
    San Francisco, CA
    MS-Off Ver
    Excel 2007
    Posts
    5

    Lock cell and grey out cells depending on cell

    I am trying to lock and grey out "A3" and "A4" depending on "A1"

    I imagine it's something like this.

    Sub workscopecell()
    
    If Target.Address = "A1" Then
            If Target.Value = "Activate" Then
                Range("A3") And Range("A4").Interior.Color = RGB(192, 192, 192)
                ActiveSheet.Cells.Locked = False
                Range("A3") And Range("A4").Locked = True
                ActiveSheet.Protect
            Else
                ActiveSheet.Unprotect
                Range("J13").Interior.ColorIndex = xlNone
            End If
        End If
      
    End Sub

  2. #2
    Forum Guru JBeaucaire's Avatar
    Join Date
    03-21-2008
    Location
    Bakersfield, CA
    MS-Off Ver
    2010
    Posts
    19,226

    Re: Lock cell and grey out cells depending on cell

    Range("A3:A4").Interior.Color = RGB(192, 192, 192)
    ...etc.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    “None of us is as good as all of us” - Ray Kroc
    “Actually, I *am* a rocket scientist.” - JB (little ones count!)

  3. #3
    Forum Moderator Richard Buttrey's Avatar
    Join Date
    02-15-2008
    Location
    Grappenhall, UK
    MS-Off Ver
    Excel for Windows & Mac - all versions.
    Posts
    6,566

    Re: Lock cell and grey out cells depending on cell

    Hi,

    What's the trigger for this? It seems that it should probably be a Worksheet Change event, but your procedure seems to be a normal sheet/module level procedure.
    If so try

    Private Sub Worksheet_Change(ByVal Target As Range)
        If Target = Range("A1") And Target.Value = "Activate" Then
            Range("A3:A4").Interior.Color = RGB(192, 192, 192)
            ActiveSheet.Cells.Locked = False
            Range("A3:A4").Locked = True
            ActiveSheet.Protect
        Else
            ActiveSheet.Unprotect
            Range("J13").Interior.ColorIndex = xlNone
    
        End If
    End Sub
    Richard Buttrey

    If this was useful then please rate it appropriately.

    Click the small star icon at the bottom left of my post.

  4. #4
    Registered User
    Join Date
    01-03-2012
    Location
    San Francisco, CA
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: Lock cell and grey out cells depending on cell

    Woohoo! It works, but it's displaying a error message- "Range("A3:A4").Interior.Color = RGB(192, 192, 192)" Is there anyway to disable to error msg?

  5. #5
    Forum Guru JBeaucaire's Avatar
    Join Date
    03-21-2008
    Location
    Bakersfield, CA
    MS-Off Ver
    2010
    Posts
    19,226

    Re: Lock cell and grey out cells depending on cell

    No, don't suppress errors, fix the code. What color did you want the interior? Grey?

    Range("A3:A4").Interior.ColorIndex = 15
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    “None of us is as good as all of us” - Ray Kroc
    “Actually, I *am* a rocket scientist.” - JB (little ones count!)

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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.2.0