How to Lock the data in a cell in excel using vba

后端 未结 5 780
鱼传尺愫
鱼传尺愫 2020-11-27 19:34

I want to stop others from editing the cell contents in my excel sheet using VBA. Is it possible to do this?

5条回答
  •  忘掉有多难
    2020-11-27 19:41

    Let's say for example in one case, if you want to locked cells from range A1 to I50 then below is the code:

    Worksheets("Enter your sheet name").Range("A1:I50").Locked = True
    ActiveSheet.Protect Password:="Enter your Password"
    

    In another case if you already have a protected sheet then follow below code:

    ActiveSheet.Unprotect Password:="Enter your Password"
    Worksheets("Enter your sheet name").Range("A1:I50").Locked = True
    ActiveSheet.Protect Password:="Enter your Password"
    

提交回复
热议问题