根据值将块单元格应用于多个单元格

Apply block cells to multiple cells depending on value

我正在尝试为多个单元格应用值 block/unblock 控件,但不幸的是,有什么想法吗?非常感谢您的帮助!

Dim Copyrange1 As String
Dim Copyrange2 As String
Dim Copyrange3 As String
Dim Copyrange4 As String
Dim Copyrange5 As String




Startrow = 14
Lastrow = 61


For n = Startrow To Lastrow
        Let Copyrange1 = "k" & Startrow
        Let Copyrange2 = "h" & Startrow
        Let Copyrange3 = "i" & Startrow
        Let Copyrange4 = "l" & Startrow
        Let Copyrange5 = "m" & Startrow


        If Range(Copyrange1).Value = "LLEGA AL ODF DESTINO" Then

            ActiveSheet.Unprotect "extend"
            Range(Copyrange2).Locked = False
            Range(Copyrange3).Locked = False
            ActiveSheet.Protect "extend"

            ActiveSheet.Unprotect "extend"
            Range(Copyrange4).Locked = False
            Range(Copyrange5).Locked = False
            ActiveSheet.Protect "extend"

         Else

            ActiveSheet.Unprotect "extend"

            Range(Copyrange2).Locked = True

            Range(Copyrange3).Locked = True
            ActiveSheet.Protect "extend"

            ActiveSheet.Unprotect "extend"
            Range(Copyrange4).Locked = True
            Range(Copyrange5).Locked = True
            ActiveSheet.Protect "extend"

         End If
 Next

并且代码适用于单个范围选择,例如范围 ("k14"),但我正在尝试对 60 行执行此操作。

Let Copyrange1 = "k" & Startrow
Let Copyrange2 = "h" & Startrow
Let Copyrange3 = "i" & Startrow
Let Copyrange4 = "l" & Startrow
Let Copyrange5 = "m" & Startrow

您只使用 Startrow。将 for 循环内的 Startrow 更改为 n.