+ Reply to Thread
Results 1 to 16 of 16

Conditional cell lock

Hybrid View

coolanks Conditional cell lock 05-29-2008, 03:19 AM
coolanks conditional lock 05-29-2008, 04:29 AM
royUK You can't use Target like... 05-29-2008, 05:42 AM
coolanks Hi roy, thanks for ur help,... 05-29-2008, 06:11 AM
royUK The code I gave you checks... 05-29-2008, 07:41 AM
  1. #1
    Registered User
    Join Date
    05-15-2008
    Posts
    20

    Conditional cell lock

    Hi Friends, am in some serious problem and hope somebody would get me out from trouble here.I have an sheet(see attached) with some dummy data, now i want to lock (with password) only those cells depending on the dropdown (highlighted in sheet).For eg,if we select A from dropdown of col c and then locked from dropdown of col D , it should lock the complete row(s) of value A in col H and rows with value B shall remain editable.Am counting on you guys to put me on track and your help would be immensely appreciated.

    Thanks
    Ankur
    Attached Files Attached Files

  2. #2
    Registered User
    Join Date
    05-15-2008
    Posts
    20

    conditional lock

    Hi , I typed in the following code for this problem.But still am not able to get the desired results.Any help from anybody??


    Private Sub Worksheet_Change(ByVal Target As Range)
    Dim Cell As Range
    Dim WS As Worksheet
    Set WS = Target.Parent
    WS.Unprotect
    For Each Cell In Target
        If Cell.Column = 3 Then
            If Cell = "LOCK" Then
                Range(Cells(Cell.Row, 1), Cells(Cell.Row, 7)).Locked = True
            ElseIf Cell = "UNLOCK" Then
                Range(Cells(Cell.Row, 1), Cells(Cell.Row, 7)).Locked = False
            End If
        End If
    Next Cell
    WS.Protect
    End Sub
    Last edited by royUK; 05-29-2008 at 05:21 AM.

  3. #3
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    You can't use Target like that, Target refers to the cell(s) selected.

    Try this amended code
    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
        If Not Target.Address = "$D$2" Then Exit Sub
    
        Dim cl     As Range
        Dim rCol   As Range
        Dim WS     As Worksheet
        Set WS = Target.Parent
        Set rCol = WS.Range(Cells(5, 8), Cells(Rows.Count, 8).End(xlUp))
        WS.Unprotect
        For Each cl In rCol
            If cl.Value = Cells(2, 3).Value And Cells(2, 4).Value = "Locked" Then
                Range(Cells(cl.Row, 1), Cells(cl.Row, 8)).Locked = True
            Else: Range(Cells(cl.Row, 1), Cells(cl.Row, 7)).Locked = False
            End If
        Next cl
        WS.Protect
    End Sub
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  4. #4
    Registered User
    Join Date
    05-15-2008
    Posts
    20
    Hi roy, thanks for ur help, but am still facing issues with the sheet.If i put value A and B alternatively in col H ,the code doesn't work anymore.Hope i have made myself clear to you.Let me know should you require more information from my side.

    Ankur

  5. #5
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    The code I gave you checks each cell in Column H of the table of data to see if it matches C2, if it does it will lock or unlock the cells based on the selection in D2

  6. #6
    Registered User
    Join Date
    05-15-2008
    Posts
    20
    Roy, Can i have urs workbook?? In my workbook its not working.....Thanks for your help

    Ankur

+ 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.6.0 RC 1