当工作表受到保护时,不应标记/取消标记复选框



我正在尝试制作一个宏,在输入新数据时添加一个新复选框,但只有在工作表不受保护时才应标记或取消标记。我尝试使用以下代码执行此操作:

Range("Z4").Select
ActiveCell.FormulaR1C1 = "=LOOKUP(2,1/(C[-15]<>""""),ROW(C[-15]))"
i = Range("Z4").Value + 1
Cells(i, 19).Select
ActiveSheet.CheckBoxes.Add(Cells(i, 19).Left, Cells(i, 19).Top, 60.75, 15).Select
With Selection
.Value = xlOff
.LinkedCell = Cells(i, 30)
.Display3DShading = False
End With
Selection.Characters.Text = "Pagado"

链接的单元格被锁定,因此在锁定时不应更改。

否则,代码的其余部分可以完美运行。

所以我通过这样做想通了,比我想的要容易。这是将两个字符串加在一起,然后保护工作表并锁定引用单元格的问题。

Cells(i, 19).Select
ActiveSheet.CheckBoxes.Add(Cells(i, 19).Left, Cells(i, 19).Top, 60.75, 15).Select
With Selection
.Value = xlOff
.LinkedCell = "$CC$" & i
.Display3DShading = False
End With
Selection.Characters.Text = "Pagado"

希望它可以帮助别人。

最新更新