+ Reply to Thread
Results 1 to 4 of 4

Protect / Unprotect causing unwanted changes to "protection properties"

Hybrid View

  1. #1
    Registered User
    Join Date
    08-26-2017
    Location
    UK
    MS-Off Ver
    2016
    Posts
    2

    Protect / Unprotect causing unwanted changes to "protection properties"

    Hello - this is my first post so I hope I am doing it right!

    I have some code to insert a row in a worksheet based on double-clicking - the inserted row auto-fills a cell with a formula from the double-clicked row.

    The formula cell is protected to ensure it can't be edited so I have included an "unprotect" command first and a "protect" command at the end to re-protect the sheet.

    The issue is that the protection properties change after running the code - initially the protection allows the user to insert or delete a row but after running the code row insertion/deletion is not allowed.

    Here is the code:

    Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
    ' Unprotect worksheet in order to autofill protected cell with formula
    ActiveSheet.Unprotect "password"
    ' code to insert row below cell which is double-clicked and autofilling a (protected) cell with a formula
    Cancel = True
    Target.Offset(1).EntireRow.Insert
    Target.EntireRow.Copy Target.Offset(1).EntireRow
    On Error Resume Next
    Target.Offset(1).EntireRow.SpecialCells(xlConstants).ClearContents
    'Turn protection back on
    ActiveSheet.Protect "password"
    End Sub



    Does anyone have any ideas how to continue to allow row insertion/deletion after running this code?

    Thanks!
    Last edited by GeeJayWhite; 08-28-2017 at 02:35 AM.

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,376

    Re: Protect / Unprotect causing unwanted changes to "protection properties"

    Record a macro when you protect the sheet. It will then include the options you select. You just have to edit the recorded code to add the password.
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Registered User
    Join Date
    08-26-2017
    Location
    UK
    MS-Off Ver
    2016
    Posts
    2

    Re: Protect / Unprotect causing unwanted changes to "protection properties"

    Thanks for your help - that worked very well for me!

  4. #4
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,376

    Re: Protect / Unprotect causing unwanted changes to "protection properties"

    You're welcome.



    If you are satisfied with the solution(s) provided, please mark your thread as Solved.


    New quick method:
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

    Or you can use this way:

    How to mark a thread Solved
    Go to the first post
    Click edit
    Click Go Advanced
    Just below the word Title you will see a dropdown with the word No prefix.
    Change to Solved
    Click Save


    You may also want to consider thanking those people who helped you by clicking on the little star at the bottom left of their reply to your question.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. ActiveSheet.Unprotect("pass") / ActiveSheet.Protect ("pass") breaks functionality
    By Proventus in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 02-02-2016, 10:30 PM
  2. Excel 2013 Performance Question: Worksheet"Sheet 1".Protect/Unprotect
    By fbplaya02 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-25-2015, 02:25 PM
  3. Unable to run code in between "Unprotect" and "Protect" object.
    By eric1234 in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 08-28-2013, 12:44 PM
  4. Protect/Unprotect Cell Range on "Double-Click"
    By NahRoots in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-17-2012, 01:13 AM
  5. Replies: 5
    Last Post: 02-14-2012, 01:45 AM
  6. Toggle "Protect/Unprotect sheet" in macro
    By aljanga in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-27-2009, 07:09 PM
  7. [SOLVED] Problem: Worksheets("New Style 2006").Unprotect Password:="naPrint"
    By Karoo News in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-30-2006, 10:45 AM

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