Excel VBA 中“!=”的等价物是什么?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11595757/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What is the equivalent of "!=" in Excel VBA?
提问by What'sUP
The problem is that !=
does not work as a function in excel vba.
问题是它!=
在 excel vba 中不起作用。
I want to be able to use
我希望能够使用
If strTest != "" Then
instead of If strTest = "" Then
If strTest != "" Then
代替 If strTest = "" Then
Is there another approach to do this besides !=
?
除此之外还有其他方法可以做到这一点!=
吗?
My function to mimic !=
is
我模仿的功能!=
是
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
回答by Steve
Because the inequality operator in VBA is <>
因为 VBA 中的不等式运算符是 <>
If strTest <> "" Then
.....
the operator !=
is used in C#, C++.
该运算符!=
用于 C#、C++。
回答by frenchie
In VBA, the !=
operator is the Not
operator, like this:
在 VBA 中,!=
操作符就是Not
操作符,像这样:
If Not strTest = "" Then ...
回答by ??c Thanh Nguy?n
Just a note. If you want to compare a string with ""
,in your case, use
只是一个注释。如果要将字符串与 比较 ""
,在您的情况下,请使用
If LEN(str) > 0 Then
or even just
甚至只是
If LEN(str) Then
instead.
反而。
回答by user1745872
Try to use <>
instead of !=
.
尝试使用<>
而不是!=
.