ThrottleWorks
Excel Ninja
Hi,
I am using below mentioned code to protect range.
However it is not working. Cells are not getting locked even after using this code.
Can anyone please help me in this.
I am using below mentioned code to protect range.
However it is not working. Cells are not getting locked even after using this code.
Can anyone please help me in this.
Code:
Option Explicit
Sub MyProtect()
'Code for protecting cells
Dim CodeSht As Worksheet
Dim TempLr As Long
Set CodeSht = ActiveWorkbook.Worksheets("TAB")
TempLr = CodeSht.Cells(CodeSht.Rows.Count, 1).End(xlUp).Row
Dim TempRng As Range
Set TempRng = CodeSht.Range(CodeSht.Cells(1, 7), CodeSht.Cells(TempLr, 10))
On Error Resume Next
ActiveWorkbook.ExclusiveAccess
TempRng.Locked = True
TempRng.Protect Password:="pass"
On Error GoTo 0
End Sub