+ Reply to Thread
Results 1 to 12 of 12

Protect/Lock specific cells independently through button

  1. #1
    Registered User
    Join Date
    04-01-2008
    Posts
    63

    Protect/Lock specific cells independently through button

    Hi everyone,

    I have the following question: I attached my file. In sheet "boekhouding" I want every cell in column H to contain a button that locks that specific row. So I can't accidently change the dropdownmenu for that row.

    Is that possible?

    I also have some sort of strange problem in worksheet "Rekeningen", Range D1-D5 is named "Grootboek" were it should be named uitgaven. I can't change the name, but it doesn't seem to matter in worksheet rekeningen (the drop down menu for uitgaven works normally), what is wrong here?

    Please help me!

    Thanks,
    Regards,

    Edward
    Attached Files Attached Files

  2. #2
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320
    I have the following question: I attached my file. In sheet "boekhouding" I want every cell in column H to contain a button that locks that specific row. So I can't accidently change the dropdownmenu for that row.
    not exactly sure what you want here.lock whole column or individual cells in that column?
    I also have some sort of strange problem in worksheet "Rekeningen", Range D1-D5 is named "Grootboek" were it should be named uitgaven.
    you had named the range twice once as Grootboek and once as
    uitgaven
    i deleted the first one from insert/names/define now its named uitgaven
    Attached Files Attached Files

  3. #3
    Forum Expert mrice's Avatar
    Join Date
    06-22-2004
    Location
    Surrey, England
    MS-Off Ver
    Excel 2013
    Posts
    4,967
    An easy way to get the row locking behaviour is to set a validation list of LOCK,UNLOCK in column H and insert the following macro in the Sheet3 tab in the VBA editor.

    Please Login or Register  to view this content.
    Now set column H as unlocked and then protect your entire worksheet.
    Martin

  4. #4
    Registered User
    Join Date
    04-01-2008
    Posts
    63

    uwww

    Thanks, but...

    I can't add a second macro (besides Boekhouding.cpysht). How do I add a second macro to this sheet?

    Furthermore, I get the error:

    Compile error: Variable not defined

    THis referring to the first target.parent.

    What should I do?

    Thanks!

  5. #5
    Forum Expert mrice's Avatar
    Join Date
    06-22-2004
    Location
    Surrey, England
    MS-Off Ver
    Excel 2013
    Posts
    4,967
    Try the attached.
    Attached Files Attached Files

  6. #6
    Registered User
    Join Date
    04-01-2008
    Posts
    63

    Thanks!

    Thanks! It seems to work, however, I still have two questions:

    1) Since I want to learn: What exactly did you do/change?
    2) Isn't it possible to put this macro in some sort of button instead of drop down menu?

    Regards,

    Edward

  7. #7
    Forum Expert mrice's Avatar
    Join Date
    06-22-2004
    Location
    Surrey, England
    MS-Off Ver
    Excel 2013
    Posts
    4,967
    I did exactly what I wrote in the original instructions - hit alt F11 to see where I put the code.

    It could be done with buttons but it a lot more messy and could cause problems if you sorted the sheet. To make the cells behave more like buttons, you can add a selection change or double click macro to toggle the value. e.g.

    Please Login or Register  to view this content.
    With some conditional formatting, this could resemble a button. Paste into the same VBA tab.

  8. #8
    Registered User
    Join Date
    04-01-2008
    Posts
    63

    Help

    Hi,

    Please help me. The first macro apperently works in the example worksheet. But when I try to apply the macro below to my own worksheet, nothing happens. Please explain to me what you did and what the macro exactly does. Thanks! (Note: instead of collumn, H, I've put the button in collumn K)

    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 = 11 Then
    If Cell = "LOCK" Then
    Range(Cells(Cell.Row, 1), Cells(Cell.Row, 10)).Locked = True
    ElseIf Cell = "UNLOCK" Then
    Range(Cells(Cell.Row, 1), Cells(Cell.Row, 10)).Locked = False
    End If
    End If
    Next Cell
    WS.Protect
    End Sub

  9. #9
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678
    Edward, please read the Forum Rules and then wrap your code with Code Tags.

  10. #10
    Registered User
    Join Date
    04-01-2008
    Posts
    63
    Please help me. The first macro apperently works in the example worksheet. But when I try to apply the macro below to my own worksheet, nothing happens. Please explain to me what you did and what the macro exactly does. Thanks! (Note: instead of collumn, H, I've put the button in collumn K)

    Please Login or Register  to view this content.

  11. #11
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678
    Edward, you may wish to try this. Right-click the appropriate sheet tab, select View Code from the context menu, then paste this:
    Please Login or Register  to view this content.
    To use, double-click in column K (you might title this column "Locked").

    A check mark will appear, and cells A:J in the same row will be locked. Double-click again, the check mark will disappear, and the cells will be unlocked.

    This is an example of Marlett checkboxes, which are easy to use and implement.
    Last edited by shg; 05-04-2008 at 12:59 PM.

  12. #12
    Forum Expert mrice's Avatar
    Join Date
    06-22-2004
    Location
    Surrey, England
    MS-Off Ver
    Excel 2013
    Posts
    4,967
    Can you please attach a copy of your workbook as its possibly some factor that I'm not aware of that's causing the problem.

+ 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