You are here:

Excel/Unprotecting dynamic rows in a protected worksheet

Advertisement


Question
Hi Jerry,

Need your help in doing the below task using Formula/Macro.

I would like to unprotect the dynamic rows where it contains the word "Production Plan (Units) - Revised" in column B.

As per this example I would like to unprotect the cells C7:H7, C10:H10, C15:H15. I want to unprotect the whole row after the cell contains particular text (i.e. "Production Plan (Units) - Revised" in this case).

Please note that range will be dynamic. Please let me know if you have any question.


https://skydrive.live.com/redir?resid=A1B8470E44E28CE2!144&authkey=!AMmQq1D4vCEcXEo

Answer
Put this event macro into the sheet module where you want this behavior.  We'll assume you've already unlocked the column B cells so they are editable while the sheet is locked.

The macro watches for changes in column B.  Anytime you edit the column B values, the cells C:H on that same row will lock/unlock based on whether or not the B value is "Production Plan (Units) - Revised"


Option Explicit

Private Sub WOrksheet_Change(ByVal Target As Range)
Dim cell As Range

Me.Unprotect "Password"      'correct the password or remove if no password

For Each cell In Target
    If Not Intersect(cell, Range("B:B")) Is Nothing Then
        Range("C" & cell.Row).Resize(, 6).Locked = (cell.Value = "Production Plan (Units) - Revised")
    End If
Next cell

Me.Protect "Password"

End Sub


About Excel
This topic answers questions related to Microsoft Excel spreadsheet (or workbook) stand-alone or Mircrosoft Office Excel including Excel 2003, Excel 2007, Office 2000, and Office XP. You can get Excel help on Excel formulas(or functions), Excell macros, charting in Excel, advanced features, and the general use of Excel. This does not provide a general Excel tutorial nor the basics of using a spreadsheet. It provides specific answers to using Microsoft Excel only. If you do not see your Excel question answered in this area then please ask an Excel question here

Excel

All Answers


Answers by Expert:


Ask Experts

Volunteer


Jerry Beaucaire

Expertise

Excel Formulas, macros, automation. Microsoft Excel MVP - 2010. Code site with free code snippets and techniques: http://sites.madrocketscientist.com/jerrybeaucaires-excelassistant/files

Experience

Microsoft Excel MVP - 2010. I have my own extensive Excel help/code site: http://sites.madrocketscientist.com/jerrybeaucaires-excelassistant/files ===================== I have been offering free assistance as an Excel aid on many web sites for many years: (http://www.excelforum.com - JBeaucaire) ======== (http://www.askmehelpdesk.com/spreadsheets - JBeaucaire) ======= (http://www.mrexcel.com/forum - jbeaucaire)

Education/Credentials
Bachelor's Degree from Azusa Pacific University in Mathematics and Music Composition

Awards and Honors
Microsoft Excel MVP 2010

©2016 About.com. All rights reserved.