我试图在VBA中使用OR循环,但不是避免使用包含字母的单元格,而是将整个数组设为“ - ”。即使我输入数字或单词,它也会用短划线取代整个数组。
Private Sub CommandButton1_Click()
Dim l As Double, c As Double
For l = 14 To 18
For c = 10 To 12
If Cells(l, c).Value <> "W" Or _
Cells(l, c).Value <> "w" Or _
Cells(l, c).Value <> "X" Or _
Cells(l, c).Value <> "x" Or _
Cells(l, c).Value <> "Y" Or _
Cells(l, c).Value <> "y" Or _
Cells(l, c).Value <> "Z" Or _
Cells(l, c).Value <> "z" Then
Cells(l, c).Value = "-"
End If
Next c
Next l
End Sub
答案 0 :(得分:2)
你需要和条件一起。
If Cells(l, c).Value <> "W" And _
Cells(l, c).Value <> "w" And _
Cells(l, c).Value <> "X" And _
Cells(l, c).Value <> "x" And _
Cells(l, c).Value <> "Y" And _
Cells(l, c).Value <> "y" And _
Cells(l, c).Value <> "Z" And _
Cells(l, c).Value <> "z" Then
答案 1 :(得分:2)
这是将任何非w-Z的单元格更改为“ - ”的简单方法:
If Cells(l, c).Value Like "[!w-zW-Z]" Then
Cells(l, c).Value = "-"
End If
答案 2 :(得分:1)
另一种有效的选择:
Select Case UCase$(Cells(l, c))
Case "W" To "Z"
Cells(l, c).value = "-"
End Select