ExcelVBA 中“ ! =”的等价物是什么?

问题是 !=不能作为 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
416787 次浏览

Because the inequality operator in VBA is <>

If strTest <> "" Then
.....

the operator != is used in C#, C++.

In VBA, the != operator is the Not operator, like this:

If Not strTest = "" Then ...

Try to use <> instead of !=.

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.