What is the equivalent of "!=" in Excel VBA?

ExcelVbaFunctionSyntaxInequality

Excel Problem Overview


The problem is that != does not work as a function in excel vba.

I want to be able to use

If strTest != "" Then instead of 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

Excel Solutions


Solution 1 - Excel

Because the inequality operator in VBA is <>

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

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

Solution 2 - Excel

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

If Not strTest = "" Then ...

Solution 3 - Excel

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.

Solution 4 - Excel

Try to use <> instead of !=.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionWhat&#39;sUPView Question on Stackoverflow
Solution 1 - ExcelSteveView Answer on Stackoverflow
Solution 2 - ExcelfrenchieView Answer on Stackoverflow
Solution 3 - ExcelĐức Thanh NguyễnView Answer on Stackoverflow
Solution 4 - ExcelSteveView Answer on Stackoverflow