MrExcel's Learn Excel #593 - Unprotect Green Cells

If you like this content, please consider visiting the video on YouTube and subscribe to the MrExcel Channel to show your support!
This video has been published on Apr 14, 2009.
Today, the questioner asks how to unprotect the green cells. There isnt any good way to do this in the Excel user interface, so in Episode 593, I use a tiny bit of VBA code to achieve the effect.

The code used in the podcast is:


Sub UnProtectGreen
For each Cell in Selection
If Cell.Interior.ColorIndex = 4 then
Cell.Locked = False
Else
Cell.Locked = True
End If
Next Cell
End Sub

This blog is the video podcast companion to the book, Learn Excel from MrExcel. Download a new two minute video every workday to learn one of the 277 tips from the book!
maxresdefault.jpg


Transcript of the video:
Hey, welcome back to the MrExcel netcast.
I'm Bill Jelen.
Today we have a question that came in one of the power Excel seminars and every once in a while you get a question that just kind of makes your head spin the guy said hey, I wanna be able to protect the entire worksheet except for the green cells.
Wow, that's a tough one. There's no good way to go through and protect everything except for the green cells and this is one where I think the best solution is to go through and use a little bit of VBA.
Here's what I'm gonna do.
I'm gonna select one of the green cells and we'll switch over to VBA with Alt+F11.
I wanna do something quick in the Immediate window, The Immediate windows control+G. I must say, print activecell.interior.colorindex.
That'll tell me that that particular green has a color index of 4, Now, we can go back up and insert a quick module here.
Insert, Module.
Now, create a new macro I'll call it Sub UnprotectGreen.
Well, say For Each cell in Selection if cell.interior.colorindex=4, then cell.locked =False Else cell.locked = True End If, and Next cell.
Now we have this tiny little macro here that will go through and basically look at all the cells in our selection if the cell is green, it's going to unlock it otherwise it will leave it as lock.
So, we'll select basically the whole area of the spreadsheet Alt+F8, will give me a list of the Macros run UnprotectGreen and we've now gone through and basically unlocked the green cells.
Final step Tools, Protection, Protect Sheet and you'll see that if I try and change one of the green cells, it lets me change it.
If I try and change any other cell, it's a protected cell.
So, now I'm sure the person who asked this question had a much more convoluted spreadsheet lots of green cells.
I guess if you had three, you could just go through and unlock them yourselves.
But certainly if you had a large spreadsheet, and for some reason you need to unlock all the green cells just the input cells using a little bit of Macro code is the way to go.
Hey, thanks for stopping by.
We'll see you next time for another netcast from MrExcel.
 

Forum statistics

Threads
1,223,276
Messages
6,171,140
Members
452,381
Latest member
Nova88

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