If/Then语句不能正确执行
问题描述:
我已经用If/Then创建了各种宏,但是这次我遇到了If/Then进程的问题。在And之后的If/Then的第二部分它不能正确执行。它只会将And之前的偏移值设为0。单元格的格式没有问题,因为当我改变它们的位置时,对于之前和之后的那个都可以正常工作。我正在提供下面的代码。If/Then语句不能正确执行
For Each cell2 In Range("E7:E" & lastrow12)
If cell2.Value = 0 Then
cell2.Offset(0, -2).Value = 0 And cell2.Offset(0, -1).Value = 0
End If
Next cell2
答
在这里你去:
For Each cell2 In Range("E7:E" & lastrow12)
If cell2.value = 0 Then
cell2.Offset(0, -2).value = 0
cell2.Offset(0, -1).value = 0
End If
Next cell2
答
And函数是一个内置函数,它被归类为一个逻辑函数,如True和True。
您不能使用合并两个语句。那就是说:
For Each cell2 In Range("E7:E" & lastrow12)
With cell2
If .Value = 0 Then
.Offset(0, -1).Value = 0
.Offset(0, -2).Value = 0
End If
End With
Next cell2