我想用两组值定义我的变量。例如,
Dim i as integer
For i = 92 to 97 and 104 to 109
你能解释一下这种方法的正确方法吗?这就是我所拥有的 -
Dim k As Integer
For k = 92 To 97
If Range("A" & k).Text = "#NUM!" Then
Range("A" & k).Select
Selection.ClearContents
Range("I" & k).Select
Selection.ClearContents
Range("J" & k).Select
Selection.ClearContents
End If
Next k
Dim j As Integer
For j = 104 To 109
If Range("A" & k).Text = "#NUM!" Then
Range("A" & j).Select
Selection.ClearContents
Range("I" & j).Select
Selection.ClearContents
Range("J" & j).Select
Selection.ClearContents
End If
Next j
我想组合变量k和j。谢谢!
答案 0 :(得分:4)
Dim k As Integer
For k = 92 To 109
If Range("A" & k).Text = "#NUM!" and (k <= 97 or k >= 104) Then
Range("A" & k).ClearContents
Range("I" & k).ClearContents
Range("J" & k).ClearContents
End If
Next k
在我看来,这似乎是合乎逻辑的方式。我也清理了所有这些选择。它们是不必要的,可能比你更麻烦。