You are here:

Excel/Unprotecting dynamic rows in a protected worksheet



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.!144&authkey=!AMmQq1D4vCEcXEo

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.

Sub UnLockRowsBasedOnCondition()
Dim ws As Worksheet

Set ws = Sheets("Sheet1")

With ws
   .Unprotect "abc"
   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
       End If
   Next c
   .Protect "abc"
End With

End Sub

---------- 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.


Hi Prabhat,

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!


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


All Answers

Answers by Expert:

Ask Experts




[Overview] Having hands-on experience with Excel, I can able to answer questions which is related to Conditional Formatting, Goal Seek, Scenarios, Subtotal, Validation, Pivot Table, Shared Workbook, Excel Sheet / Workbook Protection, Excel Settings, Excel Shortcuts and the Two Major & Massive Key Areas of Excel (i.e.) Worksheet Functions and Excel VBA (Macro).

[Services] Volunteer in many of the Excel Discussion Groups / Forums and answered more than 10,000+ questions (approx.)

[Client FAQs] My Solution Files

[Not Interested In] Chart Questions

[Something Controversial]
*50% of answers never been read by the questioner's.
*Only 5% of questioner's provide feedback about the suggested answers.


Vast Experience

Ms-Office, Oracle, Foxpro, C, COBOL etc.,

©2016 All rights reserved.