Locking and formatting cell based on variable values of other cells

PRADEEPSWALSE

New Member
Joined
Nov 27, 2018
Messages
14
Hi,

If I run macro 'LockCells' manually then it works.

Is it possible to run macro after entering value in certain cells?
 

Some videos you may like

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.

mumps

Well-known Member
Joined
Apr 11, 2012
Messages
8,744
Copy and paste this macro into the worksheet code module. Do the following: right click the tab name for your sheet and click 'View Code'. Paste the macro into the empty code window that opens up. Close the code window to return to your sheet. Enter a value in column A and press the RETURN key.
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Intersect(Target, Range("A:A")) Is Nothing Then Exit Sub
    Application.ScreenUpdating = False
    ActiveSheet.Unprotect
    Dim LastRow As Long, arr As Variant, i As Long
    LastRow = Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
    arr = Array("CL", "GP", "SB", "SF", "SP", "TB", "TP")
    For i = LBound(arr) To UBound(arr)
        Select Case True
            Case Target Like arr(i) & "*"
                With Target.Offset(, 1)
                    .Locked = True
                    .Interior.ColorIndex = 3
                End With
                Exit For
            Case Else
                With Target.Offset(, 1)
                    .Locked = False
                    .Interior.ColorIndex = xlNone
                End With
        End Select
    Next i
    ActiveSheet.Protect
    Application.ScreenUpdating = True
End Sub
 

Forum statistics

Threads
1,089,337
Messages
5,407,672
Members
403,158
Latest member
Limerick2030

This Week's Hot Topics

  • help please
    SORRY NOT ANY GOOD AT EXCEL SO HELP WOULD BE MUCH APPRECIATED this formula is in a sheet called ignore...
  • two formulas needed
    Hello, I'll try my best to explain this: First formula needed in Sheet1 cell A2: If Sheet1 cell B2 = Sheet2 cell B2 then return a 1. If not then...
  • Dynamic Counts
    Good afternoon, we are tidying up some data & the data seems to be growing quicker than we are tidying it up! What we confirm (by reviewing it...
  • Help Excel formula eliminate duplicate values and keep only 2 identical rows.
    as picture below column A has a duplicate value. but the values are not the same as the rule. sometimes 4 rows, sometimes 10 rows or 7 or 9...
  • Macro Compile Error Sub or Function not defined
    Hello, I am trying to run macros from a validation list, all macros have been created and run perfectly on there own but I'm getting a compile...
  • Last row combined with Current Region VBA
    I'm generally happy finding the last row of data through something like Lastrow = Cells(Rows.Count, "D").End(xlUp) but I don't always receive data...
Top