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

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).

xld

Banned
Joined
Feb 8, 2003
Messages
5,378
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

plost33

Well-known Member
Joined
Oct 2, 2008
Messages
866
thanks works great. can you add in a line that says if backgound color is not =6 then row is locked/protected.
 
Upvote 0

mikerickson

MrExcel MVP
Joined
Jan 15, 2007
Messages
24,348
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

xld

Banned
Joined
Feb 8, 2003
Messages
5,378
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,191,025
Messages
5,984,205
Members
439,878
Latest member
melodysc

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
Top