First of all, I am very very geek for VB codes, so please excuse my poor coding attempts
let me explain what I want to achieve.
I have cell A1, which has two text values, "yes" or "no".(by data validation)
Now if value "no" is selected, then I want cells A2:A6 locked and content cleared. and if value is changed to "Yes" then those cells should be unlocked.
following macro I have entered
Sub Lockcell()
If Sheet1!a1 = "No" Then
Range("A2:A6").Select
Selection.Locked = True
Selection.FormulaHidden = False
Selection.ClearContents
End If
End Sub
Obviously, this didnt work. On searching this forum, I got something about activesheet,
and I tried with this
Private Sub Worksheet_Change(ByVal Target As Range)
If ActiveSheet.Cells(1, 1).Text = "No" Then
ActiveSheet.Range(Cells(2, 1), Cells(6, 1)).Locked = True
Else
ActiveSheet.Range(Cells(2, 1), Cells(6, 1)).Locked = False
End If
End Sub
Please give little guidance if active.sheet command to be used.
let me explain what I want to achieve.
I have cell A1, which has two text values, "yes" or "no".(by data validation)
Now if value "no" is selected, then I want cells A2:A6 locked and content cleared. and if value is changed to "Yes" then those cells should be unlocked.
following macro I have entered
Sub Lockcell()
If Sheet1!a1 = "No" Then
Range("A2:A6").Select
Selection.Locked = True
Selection.FormulaHidden = False
Selection.ClearContents
End If
End Sub
Obviously, this didnt work. On searching this forum, I got something about activesheet,
and I tried with this
Private Sub Worksheet_Change(ByVal Target As Range)
If ActiveSheet.Cells(1, 1).Text = "No" Then
ActiveSheet.Range(Cells(2, 1), Cells(6, 1)).Locked = True
Else
ActiveSheet.Range(Cells(2, 1), Cells(6, 1)).Locked = False
End If
End Sub
Please give little guidance if active.sheet command to be used.