问题是!=
在excel vba中不起作用。
我希望能够使用
If strTest != "" Then
代替If strTest = "" Then
除!=
之外还有另一种方法吗?
我模仿!=
的功能是
Sub test()
Dim intTest As Integer
Dim strTest As String
intTest = 5
strTest = CStr(intTest) ' convert
Range("A" + strTest) = "5"
For i = 1 To 10
Cells(i, 1) = i
If strTest = "" Then
Cells(i, 1) = i
End If
Next i
End Sub
答案 0 :(得分:149)
因为VBA中的不等运算符是<>
If strTest <> "" Then
.....
运算符!=
用于C#,C ++。
答案 1 :(得分:26)
在VBA中,!=
运算符是Not
运算符,如下所示:
If Not strTest = "" Then ...
答案 2 :(得分:7)
请注意。如果您想将字符串与""
进行比较,请使用
If LEN(str) > 0 Then
甚至只是
If LEN(str) Then
代替。
答案 3 :(得分:2)
尝试使用<>
代替!=
。