one line of code needed

plost33

Well-known Member
Joined
Oct 2, 2008
Messages
866
I need a line of code that says: if background color of a cell in range E18:E3000 = 6 then remove protection/unlock that entire row.
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
Code:
Activesheet.Unprotect "password"
For Each cell In Range("E18:E3000")

If cell.Interior.ColorIndex = 6 Then

cell.EntireRow.Locked = False
End If
Next cell
Activesheet.Protect "password"
 
Upvote 0
thanks works great. can you add in a line that says if backgound color is not =6 then row is locked/protected.
 
Upvote 0
Code:
Activesheet.Unprotect "password"
For Each cell In Range("E18:E3000")
    With cell
        .EntireRow.Locked = (.Interior.ColorIndex <> 6)
    End With
Next cell
Activesheet.Protect "password"
 
Upvote 0
Patience is not one of your virtues is it?

Code:
Activesheet.Unprotect "password"
For Each cell In Range("E18:E3000")

cell.EntireRow.Locked = cell.Interior.ColorIndex <> 6
Next cell
Activesheet.Protect "password"
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,646
Messages
6,120,717
Members
448,985
Latest member
chocbudda

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top