VBA NOT Function

VBA NOT Function

Objective of VBA NOT Function

VBA NOT function is categorized as a logical function in VBA. It is a built-in function in MS Office Excel VBA. This function returns TRUE, if a condition is FALSE. And it returns FALSE, if a condition is TRUE. This is one of the most used logical operator. It works like an inverse function. It returns a Boolean value (True or False).

We can use this function as a worksheet function and also can be used in VBA. This function can be used in either procedure or function in a VBA editor window in Excel. We can use this VBA NOT function any number of times in any number of procedures or functions. In the following section we learn what is the syntax and parameters of the NOT function, where we can use this VBA NOT function and real-time examples.

Syntax of VBA NOT Function

The syntax of the VBA NOT function is

NOT (Condition/Expression)

The VBA NOT function returns a Boolean value either True or False. It returns FALSE, if a condition is TRUE. And it returns TRUE, if a condition is FALSE.

Parameters or Arguments

The NOT function contains a condition.
Where
Condition: It is a required parameter. Here we evaluate specified condition and returns TRUE or FALSE.

Where we can apply or use VBA NOT Function?

We can use this VBA NOT function in MS Office 365, MS Excel 2016, MS Excel 2013, 2011, Excel 2010, Excel 2007, Excel 2003, Excel 2016 for Mac, Excel 2011 for Mac, Excel Online, Excel for iPhone, Excel for iPad, Excel for Android tablets and Excel for Android Mobiles.

Example 1: Example on VBA NOT Function(FALSE)

Here is a simple example of the VBA NOT function. This below example macro checks a specified condition is TRUE or FALSE. The output of below macro is FALSE.

'Example on VBA NOT Function(FALSE)
Sub VBA_NOT_Function_Ex1()
        
    If Not (0 = 0) Then
        MsgBox "Result :" & True, vbInformation, "VBA NOT Function"
    Else
        MsgBox "Result :" & False, vbInformation, "VBA NOT Function"
    End If

End Sub

Output: Here is the screen shot of the first example output.
VBA NOT Function

Example 2: Example on VBA NOT Function(TRUE)

Here is a another example of the VBA NOT function. This below example macro checks a specified condition is TRUE or FALSE. The output of below macro is TRUE.

'Example on VBA NOT Function(TRUE)
Sub VBA_NOT_Function_Ex2()

    If Not (0 = 1) Then
        MsgBox "Result :" & True, vbInformation, "VBA NOT Function"
    Else
        MsgBox "Result :" & False, vbInformation, "VBA NOT Function"
    End If

End Sub

Output: Here is the screen shot of the second example output.
VBA NOT Function

Example 3: Check an inverse of TRUE

Here is a simple example of the VBA NOT function. This below example macro checks for an inverse value. The output of below macro is FALSE.

'Check an inverse of TRUE
Sub VBA_NOT_Function_Ex3()
    
    sOutput = Not (True)
    
    MsgBox "Result :" & sOutput, vbInformation, "VBA NOT Function"

End Sub

Output:Here is the screen shot of the third example output.
VBA NOT Function

Example 4: Check an inverse of FALSE

Here is a simple example of the VBA NOT function. This below example macro checks for an inverse value. The output of below macro is TRUE.

'Check an inverse of FALSE
Sub VBA_NOT_Function_Ex4()
    
    sOutput = Not (False)
    
    MsgBox "Result :" & sOutput, vbInformation, "VBA NOT Function"

End Sub

Output:Here is the screen shot of the fourth example output.
VBA NOT Function

Instructions to use Macro Codes

Here are the step by step instructions to use the VBA NOT function in Excel VBA.

  • Open an Excel workbook.
  • Press Alt+F11 to open VBA Editor window.
  • Go to Insert menu and click on module from the available options.
  • Copy above specified macros to the VBA editor.
  • Select any procedure from above codes and click on ‘Run’ command or use Keyboard shortcut ‘F5’.

List of VBA Functions:

Please click on below link to go back to see all List of VBA Functions.

VBA Logical Functions List of VBA Functions