使excel中的可编辑的单元格很less,很less的单元格需要保护

我有一个从第8行到结束,从列A到AZ的数据的Excel表格我写了一个macros,其中当用户select一个单元格时,它将采取行地址,并会提示开始列名称和结束列名称,所以工作表在这些单元格上变得焦躁不安。 问题是如果我想在最后插入行,不允许我添加。 如何在这种情况下插入一行。

这个excel分发给用户,用户应该能够添加行,但不能编辑我locking的列。 这个怎么做? 这是我写的macros:

Sub Row_Locker() Dim locat As String Dim colstart As String Dim colend As String Dim topath As String ActiveSheet.Protect Password:="mbt" ActiveSheet.Unprotect rlocat = ActiveCell.Row clocat = ActiveCell.Column colstart = InputBox("enter the start column name") colend = InputBox("enter the end column name") topath = colstart & "8" & ":" & colend & rlocat Cells.Select ' unlock all the cells Selection.Locked = False ' next, select the cells (or range) that you want to make read only, ' here I used simply A1 Range(topath).Select ' lock those cells Selection.Locked = True ' now we need to protect the sheet to restrict access to the cells. ' I protected only the contents you can add whatever you want ActiveSheet.Protect DrawingObjects:=False, Contents:=True, Scenarios:=False End Sub 

Excel工作表看起来像这样,所以如果我select黄色框,那么上面的列内容和旁边的列内容将被阻止,如果运行macros。 并为第一个input框input“N”,为第二个input框input“O” 在这里输入图像描述

尝试这个:

 ActiveSheet.Protect Password:="your pw", AllowInsertingRows:=True ' , other if needed, 

参考: WorkSheet.Protect

(Password,DrawingObjects,内容,scheme,UserInterfaceOnly,AllowFormattingCells,AllowFormattingColumns,AllowFormattingRows,AllowInsertingColumns,AllowInsertingRows,AllowInsertingHyperlinks,AllowDeletingColumns,AllowDeletingRows,AllowSorting,AllowFiltering,AllowUsingPivotTables)

expression式:表示工作表对象的variables。