Macro help to see if cells lock after data input.

ghrek

Active Member
Joined
Jul 29, 2005
Messages
426
Hi
I have a macro but dont unerstand it at all. sorry.

I have is a workbook that has certain cells unlocked so data can be input and others locked. The unlocked cells are coloured yellow.
What im trying to do is when data is input into a unlocked cell I need it locked and the yellow in the cell turn white.

Any ideas, Macro below..
VBA Code:
Private Sub Worksheet_Change(ByVal Target as Range) 
    Target.Font.ColorIndex = 5
For Each rng In ActiveSheet.Range("B4:C9")

        If Not IsEmpty(rng) Then

            rng.Locked = True

        Else

            rng.Locked = False

        End If

    Next rng
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
I think you want something like this

VBA Code:
Private Sub Worksheet_Change(ByVal Target as Range) 
    If Target.Interior.ColorIndex = 19 And Target<>"" Then   'change 19 to 6 for bright yellow
        Target.Interior.ColorIndex=-4142
        Target.Locked=True
    End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,813
Messages
6,121,706
Members
449,049
Latest member
THMarana

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