+ Reply to Thread
Results 1 to 5 of 5

Allowing worksheet to be updated and keep protection in place

  1. #1
    Registered User
    Join Date
    01-09-2014
    Location
    North Carolina
    MS-Off Ver
    Excel 2007
    Posts
    3

    Allowing worksheet to be updated and keep protection in place

    I have attempted to allow specific rows to be hidden and require the macro to protect/unprotect in the process. The macro works without a hitch until I add the protect/unprotect requirement. I'm a novist exploring macros to expand Excel. Here is what I am using:

    Private Sub macrounprotect1()

    Sheet1.Unprotect Password:="Money1"

    End Sub

    Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As Boolean)

    End Sub

    Private Sub Worksheet_Change(ByVal Target As Range)

    If (Range("c11").Value = "Real Estate Secured") Then
    Rows("13:27").EntireRow.Hidden = False
    Rows("28:47").EntireRow.Hidden = True
    End If
    If (Range("c11").Value = "Unsecured") Then
    Rows("28:38").EntireRow.Hidden = False
    Rows("13:27").EntireRow.Hidden = True
    Rows("39:47").EntireRow.Hidden = True
    End If
    If (Range("c11").Value = "Secured Other") Then
    Rows("39:47").EntireRow.Hidden = False
    Rows("28:38").EntireRow.Hidden = True
    Rows("13:27").EntireRow.Hidden = True
    End If


    End Sub

    Private Sub Worksheet_PivotTableUpdate(ByVal Target As PivotTable)

    End Sub

    Private Sub Worksheet_SelectionChange(ByVal Target As Range)

    End Sub

    Private Sub macroprotect2()

    Sheet1.Protect Password:="Money1"

    End Sub

  2. #2
    Forum Expert
    Join Date
    10-09-2012
    Location
    Dallas, Texas
    MS-Off Ver
    MO 2010 & 2013
    Posts
    3,049

    Re: Allowing worksheet to be updated and keep protection in place

    I am not sure exactly what you are trying to accomplish. What is not working correctly? What are you trying to do? What portion of the problem is encountering errors?
    Please ensure you mark your thread as Solved once it is. Click here to see how.
    If a post helps, please don't forget to add to our reputation by clicking the star icon in the bottom left-hand corner of a post.

  3. #3
    Registered User
    Join Date
    01-09-2014
    Location
    North Carolina
    MS-Off Ver
    Excel 2007
    Posts
    3

    Re: Allowing worksheet to be updated and keep protection in place

    Errors are showing with the hidden rows. The rows shown in the worksheet are visible only when the cell containing "Real Estate Secured" is shown, as an example. All other rows are hidden; "Unsecured" and "Secured Other." When I placed protect/unprotect in the mix, the macro no longer works. The macro has to allow the sheet to become unprotected to hid and unhid the rows. The the protection needs to be placed to protect cell contents. Hopefully that is a better explanation....

  4. #4
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: Allowing worksheet to be updated and keep protection in place

    You're using the worksheet_change event incorrectly. Notice the use of the "Target" range which is the cell that is being changed. I am of course assuming you want this code to be run when you enter data into cell C11.

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    01-09-2014
    Location
    North Carolina
    MS-Off Ver
    Excel 2007
    Posts
    3

    Re: Allowing worksheet to be updated and keep protection in place

    This is a much cleaner solution to what I was trying to achieve. Thanks....it works great.

+ 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. Allowing User to import worksheet from another workbook
    By exlgh91 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-14-2013, 09:32 AM
  2. Allowing Grouping in a protected worksheet
    By ashylib in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-13-2012, 02:58 AM
  3. [SOLVED] Worksheet protection is gone and only wokbook protection can be se
    By Eric C. in forum Excel General
    Replies: 4
    Last Post: 05-02-2006, 11:55 AM
  4. Replies: 1
    Last Post: 10-21-2005, 02:05 PM
  5. Protecting a worksheet but still allowing Outlining/Grouping?
    By Joe Schmoe in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-02-2005, 03:05 PM

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