Excel Functions Tutorials

- VBA
- VBA Tutorial
- VBA Functions in Excel
- VBA ArrayList
- VBA Arrays Function in Excel
- VBA Activate Sheet
- VBA Break
- VBA Borders
- VBA Boolean
- VBA ByRef
- VBA Code
- VBA Const
- VBA Class Modules
- VBA Count
- VBA COUNTA
- VBA COUNTIF
- VBA Comment Block
- VBA Match Function
- VBA LEFT Function
- VBA Right Function
- VBA Like
- VBA LEN
- VBA Long
- VBA Today
- VBA Now
- VBA Time Function
- VBA Timer
- VBA TimeValue
- VBA Weekday
- VBA ROUND
- VBA RoundUp
- VBA Random Numbers
- VBA ReDIM Function
- VBA Rename Sheet
- VBA Protect Sheet
- VBA Remove Duplicates
- VBA Concatenate
- Copy Paste in VBA
- VBA Paste
- VBA Print
- VBA Date Function
- VBA DateDiff Function
- VBA DateAdd Function
- VBA DatePart
- VBA Data Type
- VBA Dictionary
- VBA Debug Print
- VBA Charts
- VBA CDBL
- VBA CSTR
- VBA Chr
- VBA ChDir
- VBA ENUM
- VBA RegEx
- VBA Mid Function
- VBA Max
- VBA Find Function
- VBA Find and Replace
- VBA Trim Function
- VBA Text
- VBA OFFSET Function
- VBA MOD Function
- VBA Split Function
- VBA UBound Function
- VBA Union
- VBA Transpose
- VBA INT
- VBA InStr
- VBA INSTRREV
- VBA Intersect
- VBA Integer
- VBA DIR Function
- VBA OR Function
- VBA AND
- VBA Operators
- VBA Not Equal
- VBA Worksheet Function
- VBA Workbook
- VBA ThisWorkbook
- VBA Worksheets
- VBA Write Text File
- VBA Hyperlinks
- VBA String Functions
- VBA StrComp
- VBA StrConv
- VBA Sub
- VBA Call Sub
- VBA End
- VBA Wait
- VBA Option Explicit
- VBA SubString
- VBA Subscript Out of Range
- VBA IIF
- VBA IF OR
- VBA IFERROR
- VBA On Error
- VBA OverFlow Error
- VBA 1004 Error
- VBA Error Handling
- VBA Type
- VBA Type Mismatch Error
- VBA IsEmpty
- VBA ISNULL
- VBA Input Box
- VBA MsgBox
- VBA Text Box
- VBA Format
- VBA Format Number
- VBA Conditional Formatting
- VBA AutoFill
- VBA AutoFilter
- VBA Color Index
- VBA Font Color
- VBA Clear Contents
- VBA Collection
- VBA Paste Special
- VBA Progress Bar
- VBA GoTo
- VBA Userform
- VBA Close UserForm
- User Defined Function in Excel VBA
- VBA Outlook
- VBA JOIN
- VBA LCase
- VBA UCase
- VBA Select Case
- VBA Select Cell
- VBA Selection
- VBA Active Cell
- VBA Set
- VBA Sleep
- VBA Pause
- VBA Range Objects
- VBA Range Cells
- VBA UsedRange
- VBA Loop
- VBA Break For Loop
- VBA For Each Loop
- VBA For Next Loop
- VBA Do Until Loop
- VBA File Copy
- VBA FileDialog
- VBA FileSystemObject (FSO)
- VBA Cells
- VBA Last Row
- VBA Insert Row
- VBA Hide Columns
- VBA New Line
- VBA GetOpenFilename
- VBA GetObject
- VBA Delete File
- VBA Delete Row
- VBA Insert Columns
- VBA Delete Column
- VBA Val
- VBA Value
- VBA Variant
- VBA Variable Declaration
- VBA Global Variables
- VBA Pivot Table
- VBA Refresh Pivot Table
- VBA PowerPoint
- VBA Send Email from Excel

- Financial Functions in Excel (17+)
- Logical Functions in Excel (15+)
- TEXT Functions in Excel (29+)
- Lookup Reference in Excel (44+)
- Maths Functions in Excel (52+)
- Date and Time Function in Excel (22+)
- Statistical Function in Excel (50+)
- Information Functions in Excel (5+)
- Excel Charts (48+)
- Excel Tools (98+)
- Excel Tips (178+)

Related Courses

## “Not Equal” Operator in VBA

Usually, we do a logical test “whether something is equal to other thing or not”. In some cases, we need to do the **“inequality”** test as well. **Inequality** test is nothing but not equal test. Generally, we say if something is equal to other thing or not, if it is equal performs some kind of task if not different task. Similarly using **Inequality** test also we can do some kind of operation. “NOT EQUAL” in VBA is represented by the combination of greater than and less than symbols. If both these operators combined then it becomes not equal symbol i.e. **“<>”**.

### How Not Equal to Works in Excel VBA?

VBA Not equal works exactly opposite to the logic of equal to operator. Equal to operator returns TRUE if the supplied test is satisfied is not it will return FALSE. For example, if you say 10 = 10 it will return TRUE or else FALSE.

On the other side “Not Equal” works in the opposite direction, if the supplied logical test is not equal then only it will return TRUE or else FALSE.

For example, if you say 10 <> 10 it will return FALSE because 10 is equal to 10. In order to get the TRUE result one value should not be equal to the other value.

**Examples of Not Equal to in Excel VBA**

Below are the examples of not equal to operator in Excel VBA.

#### Example #1

Now we will see how to use VBA Not Equal (<>) sign practically. Look at the below piece of code.

**Code:**

Sub NotEqual_Example1() Dim k As String k = 100 <> 100 MsgBox k End Sub

Here we are testing whether the number 100 is not equal to the number 100. For sure we know number 100 is equal to 100, so the result will be FALSE.

4.6 (247 ratings)

Now I will change the equation.

**Code:**

Sub NotEqual_Example1() Dim k As String k = 100 <> 99 MsgBox k End Sub

Now the test is whether number 100 is not equal to 99. So the result will be TRUE.

#### Example #2

Now we will see how to use this not equal operator in real time examples. For the demonstration, I have created some data.

We have two values, “Value 1” and “Value 2”.

Now my requirement is if the Value 1 is not equal to Value 2 then I need the result as “Different” or else I need the result as “Same”.

**Step 1: **Define a variable as an Integer.

**Code:**

Sub NotEqual_Example2() Dim k As Integer End Sub

**Step 2: **Open FOR NEXT LOOP from 2 to 9.

**Code:**

Sub NotEqual_Example2() Dim k As Integer For k = 2 To 9 Next k End Sub

**Step 3: **Inside the loop, we need to test whether value 1 is not equal to value 2. Since we need our own results we need to use IF Condition.

**Code:**

Sub NotEqual_Example2() Dim k As Integer For k = 2 To 9 If Cells(k, 1) <> Cells(k, 2) Then Cells(k, 3).Value = "Different" Else Cells(k, 3).Value = "Same" End If Next k End Sub

If condition tests whether the value 1 is not equal to value 2 or not. If not equal it will return “Different”, if equal it will return “Same”.

You can copy and paste the below VBA code.

Copy this code to your module and run using F5 key or manually. This will return a result like this.

### Hide and Unhide Sheets with Not Equal Sign

The various ways of using not equal sing are enormous. We can use this sign to fulfill our needs.

#### #1 – Hide All Sheets except One Sheet

We have seen this kind of situations many times. We needed to hide all the sheets except the particular sheet.

For example, if you want to hide all sheets except the sheet name “Customer Data” then you can use this code.

**Code:**

Sub Hide_All() Dim Ws As Worksheet For Each Ws In ActiveWorkbook.Worksheets If Ws.Name <> "Customer Data" Then Ws.Visible = xlSheetVeryHidden End If Next Ws End Sub

**Note:**Change the worksheet name to your worksheet name.#### #2 – Unhide All Sheets except One Sheet

Similarly, we can also unhide all sheets except the one sheet. Use below code to do this.

**Code:**

Sub Unhide_All() Dim Ws As Worksheet For Each Ws In ActiveWorkbook.Worksheets If Ws.Name <> "Customer Data" Then Ws.Visible = xlSheetVisible End If Next Ws End Sub

You can download this VBA Not Equal to Excel template here – VBA Not Equal Operator Template

### Recommended Articles

This has been a guide to VBA Not Equal. Here we look at how to use the Logical Operator “Not Equal to” in VBA along with practical examples and downloadable excel sheets. Below are some useful VBA articles related –

- Examples of Debug Print in VBA Excel
- File System Object (FSO)in VBA
- What does StrConv do in VBA Excel?
- Integer in Excel VBA
- Combo Box in VBA
- Using Message Box in VBA
- InputBox Examples in VBA
- How to Format in VBA?

- 3 Courses
- 12 Hands-on Projects
- 43+ Hours
- Full Lifetime Access
- Certificate of Completion