Consulting

Results 1 to 4 of 4

Thread: Solved: Unprotecting Cells

  1. #1
    VBAX Regular
    Joined
    Oct 2010
    Location
    Texas
    Posts
    93
    Location

    Solved: Unprotecting Cells

    Hello Everyone,

    I have a question about a data entry worksheet. A user will select an item from a drop down window at cell e38. An 'If' formula in cell g38 will display a statement based on the selection made by the user at cell e38. Once the selection is made from the drop down window and the message is displayed the user then enters a value in cell L38. The user enters the data saves and clears the inputs and then starts again. I'm using L38 to collect data from more than one of the items in the drop down window. This is working fine so far. The problem I'm having is with protecting worksheet. I would like cell L38 to protected and unaccessible to the user unless certain items are selected from the drop down window (ex: Product A or Product B. I've locked cell L38 so when the worksheet is protected can't access it. This works fine. The code I'm using to try and unlock the cell when Product A or B is selected is working. This is what I have so far:

    [vba]
    If wksUserInput.Range("InputStyle") <> "Product A" Then
    wksUserInput.Unprotect Password:="pencil"
    wksUserInput.Range("l38").Locked = True
    wksUserInput.Protect _
    Password:="pencil", _
    UserInterfaceOnly:=True, _
    AllowFormattingCells:=True
    End If
    If wksUserInput.Range("InputStyle") = "Product A" Then
    wksUserInput.Unprotect Password:="pencil"
    wksUserInput.Range("l38").Locked = False
    wksUserInput.Protect _
    Password:="pencil", _
    UserInterfaceOnly:=True, _
    AllowFormattingCells:=True
    End If[/vba]

    I also have the same code for Product B. The code for both Product A and B work fine independently. That is if I want to use cell L38 to collect data from only one of these items. Can an 'If, Then' statement be constructed to unprotect cell L38 if either Product A or B is selected from the drop down window? I tried using and If Or statement like:
    If wksUserInput.Range("InputStyle") = "Product A" or "Product B" Then....
    But this didn't work.
    Any help you can provide will be greatly appreciated.

    Thank you.
    Last edited by Bob Phillips; 01-06-2011 at 12:53 PM. Reason: Added VBA Tags

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [vba]

    With wksUserInput

    .Unprotect Password:="pencil"

    If .Range("InputStyle") = "Product A" Or .Range("InputStyle") = "Product B" Then

    .Range("l38").Locked = False

    Else
    .Range("l38").Locked = Truendif

    .Protect Password:="pencil", _
    UserInterfaceOnly:=True, _
    AllowFormattingCells:=True
    End If
    End With
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    VBAX Regular
    Joined
    Oct 2010
    Location
    Texas
    Posts
    93
    Location
    xld,
    Your the best!

    Thanks again for your help!

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Logic a bit wrong

    [vba]

    With wksUserInput

    .Unprotect Password:="pencil"

    If .Range("InputStyle") = "Product A" Or .Range("InputStyle") = "Product B" Then

    .Range("l38").Locked = False

    Else

    .Range("l38").Locked = True
    End If

    .Protect Password:="pencil", _
    UserInterfaceOnly:=True, _
    AllowFormattingCells:=True
    End With
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

Posting Permissions

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