+ Reply to Thread
Results 1 to 7 of 7

unprotect cells range

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    08-10-2010
    Location
    Tavira, POrtugal
    MS-Off Ver
    Excel 2010
    Posts
    132

    unprotect cells range

    Good afternoon.

    sorry to bother again. but will you can help me. is that I am trying to format a group of cells, as follows.

    if C17 contain a value, free from the E17 cell to AI17 in order to get access to write.

    and this format would be equal from C17 to C167.


    Last edited by Birnen; 09-15-2010 at 10:42 AM.

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: open cells range

    Let me be the first to say..."Huh?"
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Forum Contributor
    Join Date
    08-10-2010
    Location
    Tavira, POrtugal
    MS-Off Ver
    Excel 2010
    Posts
    132

    Re: unprotect cells range to write

    [QUOTE=Birnen;2382735]Good afternoon.

    sorry to bother again. but will you can help me. is that I am trying to format a group of cells, as follows.

    if C17 contain a number, unprotect the range from, E17 cell to AI17, in order to get access to write.

    and this format would be equal from C17 to C167.



  4. #4
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: unprotect cells range

    1) Put this macro into the ThisWorkbook module, edit it to refer to the correct sheet and the correct password.
    Private Sub workbook_Open()
        Sheets("Sheet1").Protect "password", UserInteraceOnly:=True
    End Sub

    Even though the sheet is protected, setting the UserInterfaceOnly flag when the workbook opens allows VBA to make changes to the sheet without protecting/unprotecting over and over.


    2) Place this macro into the Sheet module:
    Private Sub Worksheet_Change(ByVal Target As Range)
    Dim cell As Range
    
    On Error Resume Next
        For Each cell In Target
            If Not Intersect(cell, Range("C17:C167")) Is Nothing Then
                If IsNumeric(cell) And cell <> 0 Then _
                    Range("E" & cell.Row).Resize(1, 31).Locked = False
            End If
        Next cell
    
    End Sub

    As you work on the sheet, if you place a number into any cell in range C17:C167, that row will be unlocked. Happens in realtime.
    Last edited by JBeaucaire; 09-20-2010 at 06:21 PM.

  5. #5
    Forum Contributor
    Join Date
    08-10-2010
    Location
    Tavira, POrtugal
    MS-Off Ver
    Excel 2010
    Posts
    132

    Re: unprotect cells range

    Quote Originally Posted by JBeaucaire View Post
    1) Put this macro into the ThisWorkbook module, edit it to refer to the correct sheet and the correct password.
    Private Sub workbook_Open()
        Sheets("Sheet1").Protect "password", UserInteraceOnly:=True
    End Sub

    Even though the sheet is protected, setting the UserInterfaceOnly flag when the workbook opens allows VBA to make changes to the sheet without protecting/unprotecting over and over.


    2) Place this macro into the Sheet module:
    Private Sub Worksheet_Change(ByVal Target As Range)
    Dim cell As Range
    
        For Each cell In Target
            If Not Intersect(cell, Range("C17:C167")) Is Nothing Then
                If IsNumeric(cell) And cell <> 0 Then _
                    Range("E" & cell.Row).Resize(1, 31).Locked = False
            End If
        Next cell
    
    End Sub

    As you work on the sheet, if you place a number into any cell in range C17:C167, that row will be unlocked. Happens in realtime.


    give me error in IsNumeric...

  6. #6
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: unprotect cells range

    Quote Originally Posted by Birnen View Post
    give me error in IsNumeric...
    I've edited macro #2 above to try and resolve that.

  7. #7
    Forum Guru
    Join Date
    08-05-2004
    Location
    NJ
    MS-Off Ver
    365
    Posts
    13,582

    Re: unprotect cells range

    This is less secure as people can copy and paste items in but if they are manually entering data, you can use Data Validation to protect those cells.

    Select E17:AI167, then go to Data Validation>Custom
    Uncheck "Ignore blanks"
    enter =LEN($C17)>0 ENTER
    Type in an appropriate Error Alert "Column C must be filled in first."
    Hit OK
    ChemistB
    My 2?

    substitute commas with semi-colons if your region settings requires
    Don't forget to mark threads as "Solved" (Edit First post>Advanced>Change Prefix)
    If I helped, Don't forget to add to my reputation (click on the little star at bottom of this post)

    Forum Rules: How to use code tags, mark a thread solved, and keep yourself out of trouble

+ 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