I have a table in excel: containing the following headers: (A) Date & time, (B) Condition,(C) Energy,(D) Calculated val.
I want to lock cell C and D if cell B contains "ISO" and if it doesn't contain "ISO I want the c and D cell to be unlocked so I can manually input values in.
Cell C recalls a value in another tab/sheet in the same workbook, same for cell D.
I have tried using
Dim rng As Range
With Worksheets("sheet2")
For Each rng In .Range("B7:B10004")
Select Case LCase(rng.Value2)
Case "iso", "ISO"
rng.Offset(0, 1).Locked = True
Case "select"
rng.Offset(0, 1).Locked = True
Case Else
'do nothing if not ISO,iso or select
End Select
Next rng
End With
Setting Range.locked itself doesnt lock cells unless you protect the worksheet So add a new line to lock sheet using VBA - ActiveSheet.Protect
refer docs - https://docs.microsoft.com/en-us/office/vba/api/excel.worksheet.protect
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.