Excel/Unprotecting dynamic rows in a protected worksheet
QUESTION: Hi Dear,
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.
ANSWER: To insert the below code into your workbook, open VBA editor (Alt+F11),
Insert -> Module
Copy the below code, then Paste into the new module,
Save, Then Close Editor
I used the password as "abc" change it to your needs.
Dim ws As Worksheet
Set ws = Sheets("Sheet1")
For Each c In .Range("B2:B" & Cells(Rows.Count, "B").End(xlUp).Row)
If InStr(1, "Production Plan (Units) - Revised", c.Value) Then
c.EntireRow.Locked = False
---------- FOLLOW-UP ----------
This code works perfectly.
But I do not want to unprotect the entire row (c.EntireRow.Locked = False).
I want to unprotect the row starting from C3 and It might end it anywhere, as data is dynamic. It ends here at H6. It might end at Z6 also.
Hope you got it. Could you please incorporate these things in the code and send it to me. Thanks a ton.
Change this line c.EntireRow.Locked = False
The columns are specifically declared in the below code <u>
Range("C" & c.Row & ":H" & c.Row).Locked = False
<u>The Right Side Last Column will be automatically picked by excel based on the last entry of that row.
Range("C" & c.Row & ":" & Cells(c.Row, Columns.Count).End(xlToLeft).Address).Locked = False
Hope that helps!
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