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

时间:2015-01-20 17:02:32

标签: excel vba for-loop block cells

我试图对多个单元格应用值块/解除阻止控制但不幸的是,有什么想法吗?我真的很感激你的帮助!

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

并且代码可以使用范围选择,例如Range(“k14”),但我尝试为60行执行此操作。

1 个答案:

答案 0 :(得分:0)

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

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