CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Mar 2009
    Posts
    2

    unlock cell based on content from another cell

    I am trying to build a report form for my local volunteer fire department.

    I need to be able to unlock cells g12 and af12 based on the content of cell e9. I am not a code writer but here is what I have and it is not working.

    By the way the whole sheet is protected and only cells needing to be edited are formated to be unlocked. NO PASSWORD

    Private Sub Worksheet_Change(ByVal Target As Range)
    If Range("E9") = "WF-" Then
    Range("G12, AF12").Locked = False
    Else: Range("G12,AF12").ClearContents
    End If

    Am I missing something or do I just have it too simple.

    I tried to run this code but I get a "Unable to set the locked property of the Range class" if E9="WF-" Otherwise, -IF e9 does not ="WF-" I come up with and error that says "the cell or chart you are trying to change is protected and therefore read-only." "To modify a protected cell or chart, first remove protection using the unprotect sheet command...)

  2. #2
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: unlock cell based on content from another cell

    You probably connect using an older method for a different version of Office. Show more of your code, and the Office version used.
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  3. #3
    Join Date
    Mar 2009
    Posts
    2

    Re: unlock cell based on content from another cell

    Hi, I am using office 07 but the report form will be run on the 03 version. I am using vb 6.3 (comes with office 07)

    This is all of the code that I have for this particular need. Will I need a more complex code?

    Here is another code that I tried but also without success.

    Private Sub Worksheet_SelectionChange(ByVal Target As Range)

    If Not Intersect(Target, Range("e9")) Is Nothing Then
    Select Case Target.Cells(1, 1).Value
    Case "WF-"
    ActiveSheet.Unprotect PW
    Application.EnableEvents = False
    Range("G12").MergeArea.Locked = False
    Application.EnableEvents = True
    ActiveSheet.Protect PW
    End Select
    End If
    Last edited by 2funny4words; March 9th, 2009 at 10:17 PM.

  4. #4
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: unlock cell based on content from another cell

    1) Use CODE TAGS so we can read your mess...
    Code:
    ' like this
    2) You're using VBA, so you should just record a MACRO of what you want to do, and then look at the code.
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  5. #5
    Join Date
    Feb 2002
    Location
    Makati City, Philippines
    Posts
    1,054

    Re: unlock cell based on content from another cell

    There is an almost similar situation here: http://www.codeguru.com/forum/showthread.php?t=468069

    See Post#8
    Marketing our skills - please participate in the survey and share your insights
    -

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured