I'm trying to disable the range of cells on another sheet ( say Sheet4) based on the value in the current sheet(say Sheet1)
I have tried to disable the values in the sheet4("M4,M6,M8,M10,M12") based on the values in sheet1("C5") by using worksheet change function.
With Sheet1 I have used the below code and getting the error message
Subscript Out of Range
Private Sub Worksheet_Change(ByVal Target As Range)
Dim myRng As Range
Dim Cancel As Boolean
If Not Intersect(Target, Me.Range("C5")) Is Nothing Then
Set myRng = ThisWorkbook.Worksheets("Sheet4").Range("M4,M6,M8,M10,M12")
Me.Unprotect Password:=SHEET_PASSWORD
If Me.Range("C5").Value = "Yes" Then
myRng.Locked = False
Else
myRng.Locked = True
ThisWorkbook.Worksheets("Sheet4").Range("M4,M6,M8,M10,M12") = ""
End If
Me.Protect Password:=SHEET_PASSWORD
End If
End Sub
If I choose "Yes" in the cell value C5 in Sheet1, the cell values (M4,M6,M8,M10,M12) in sheet4 should be enabled. If i choose "No" in the cell value C5 in Sheet1, the cell values (M4,M6,M8,M10,M12) in sheet4 should be disabled.
Sheet1andSheet2in your text but you haveSheet4in your code (reading minimal reproducible example might help). AlsoChangeEventFlagis not defined and this code cannot run because anEnd Ifis missing. Please edit and improve your question. Also tell in which line you get errors and which. And actually you didn't ask a question. - Pᴇʜ