EXCEL vb 循环语句

2025-04-30 12:24:21
推荐回答(3个)
回答1:

Sub xx()
'条件锁定单元格
ActiveSheet.Unprotect
Cells.Locked = False
For i = 32 To 52
    If Cells(i, 1) = "NEW" Or Cells(i, 1) = "OBS" Or Cells(i, 1) = "DAL" Then
        Range("K" & i & ":L" & i).Locked = True
    ElseIf Cells(i, 1) = "ADD" Or Cells(i, 1) = "EXP" Or Cells(i, 1) = "REV" Then
        Range("C" & i, "H" & i).Locked = True
    End If
Next
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
End Sub

回答2:

没看懂你的行列关系,我猜是不是这样
sub test()
for i=35 to 52
if range("A"&i)="new" o rrange("A"&i)="obs" or range("A"&i)="dal" then
range("l"&i).locked=true
range("k"&i).locked=true
elseif
range("A"&i)="add" o rrange("A"&i)="exp" or range("A"&i)="rev" then
range("c"&i).locked=true
range("h"&i).locked=true
end if
next
end sub

回答3:

锁定单元格是啥意思?