Macro help to see if cells lock after data input.

ghrek

Active Member
Joined
Jul 29, 2005
Messages
301
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

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.

Dermot

Board Regular
Joined
Aug 11, 2006
Messages
139
Office Version
  1. 365
Platform
  1. Windows
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
 

Forum statistics

Threads
1,141,818
Messages
5,708,766
Members
421,588
Latest member
Wawie

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