Protect Cells on Color basis

deepak_4you

New Member
Joined
Dec 29, 2010
Messages
17
Hi All,

Can anyone tell me the VB script where i can lock all cells which are not colored? or colored in white.

Doing that users who will use files can only change colored cells (say yellow & green)

Regards

Deepak Sharma
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
Hi Deepak Sharma,

You can try this code to lock all cells, then unlock cells with colors.
You'll need to unprotect sheet before running and protect sheet after running
(either manually or by adding that to this macro).

Code:
Sub LockWhiteCells()
    Dim c As Range
    ActiveSheet.Cells.Locked = True
    For Each c In ActiveSheet.UsedRange
        If c.Interior.ColorIndex <> 2 And _
            c.Interior.ColorIndex <> -4142 Then
            c.Locked = False
        End If
    Next c
    Set c = Nothing
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,583
Messages
6,120,383
Members
448,956
Latest member
JPav

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