Consulting

Results 1 to 8 of 8

Thread: Activating a column based in the other column value

  1. #1
    VBAX Mentor
    Joined
    Sep 2007
    Posts
    405
    Location

    Activating a column based in the other column value

    Hello...

    can this be done using formula..

    Based on values in Column C, Column E
    should be unlocked. For example, if the value in C3 is Yes, E3
    should be unlocked but should be locked for all other values of
    C3. Similar for any input in Column C, Column E should be locked / unlocked
    as approriate.

    Can you please help me with this

    -Sindhuja

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Try this event code

    [[vba]


    Private Sub Worksheet_Change(ByVal Target As Range)

    If Target.Cells.Count > 1 Then Exit Sub

    If Not Intersect(Target, Me.Columns(3)) Is Nothing Then

    Target.Offset(0, 2).Locked = Target.Value2 <> "Yes"
    End If
    End Sub[/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 Newbie
    Joined
    Sep 2011
    Posts
    5
    Location
    good job.happy everyday please.


    _________________________________________________________________
    I live my life in colour and see in soundMake sure you are heard!


  4. #4
    VBAX Mentor
    Joined
    Sep 2007
    Posts
    405
    Location
    Thanks for the coding.

    Am able to edit column E even if the cell in column C is blank or any other value.

    -Sindhuja
    Attached Files Attached Files

  5. #5
    VBAX Expert
    Joined
    Sep 2010
    Posts
    604
    Location
    Locking a cell won't prevent editing. You additionally need to Protect the sheet.

    I'm a bit of a laymen at writing code, but by mirroring some of the basics XLD provided, here's my stab at it.

    Seems to work fine in my testing.
    [vba]
    Private Sub Worksheet_SelectionChange(ByVal Target As Range)

    With Target

    If .Cells.Count > 1 Then Exit Sub

    ActiveSheet.Unprotect

    Me.Columns(3).Locked = False ' Comment this out if you want Column C to be protected

    If Not Intersect(Target, Me.Columns(5)) Is Nothing Then

    If UCase(.Offset(0, -2).Value2) = "YES" Then

    .Locked = False

    Else

    .Locked = True

    End If
    End If

    End With

    ActiveSheet.Protect

    End Sub
    [/vba]

  6. #6
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    The code only locks/unlocks column E if you make a change in column C.
    ____________________________________________
    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

  7. #7
    VBAX Regular
    Joined
    Sep 2011
    Posts
    15
    Location
    Great answers ... appreciated

  8. #8
    VBAX Mentor
    Joined
    Sep 2007
    Posts
    405
    Location
    Sorry.. still am not able to get the output... am not sure where am going wrong...

    I copied the coding in the worksheet.

    -Sindhuja

Posting Permissions

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