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

## What is OR Function in VBA?

In excel logical functions is the heart of the formulas we use on a daily basis. Logical functions are there to conduct the logical test and gives result in Boolean data type i.e. either TRUE or FALSE. Some of the logical formulas in excel are “IF, IFERROR, ISERROR, AND, and OR excel function”. I hope you have used them quite often as a worksheet function. In VBA too we can use all of them and in this article, we will explain to you the ways of using “VBA OR” function.

What is the first thing comes to your mind when you think of the word “OR”?

In simple terms “OR” means **“either this or that”**

With the same idea OR is a logical function which gives the result as TRUE if any one of the logical tests is TRUE and gives FALSE as the result if none of the logical tests are TRUE.

This works exactly opposite of VBA AND function. AND function returns TRUE only if all the logical conditions are TRUE, if any one of the condition is not satisfied then we will get FALSE as the result.

### Formula of VBA OR Function

Let me frame a syntax for you to understand the function.

[Logical Test] OR [Logical Test] OR [Logical Test]

First, we need to mention what is the logical test then mention the word OR then mention what is the second logical test. If you wish to conduct more logical test then mention the word OR after everting logical test.

Off all the logical tests you do, if any one of the tests is satisfied or true then we will get the result as TRUE if none or satisfied then the result is FALSE.

### Examples of Using OR Function in VBA

We will show you a simple example of using the OR function in VBA.

To understand the logical VBA function OR let me give you an example. Let’s say we want to conduct the logical test whether the number 25 is greater than 20 or number 50 is less than 30.

**Step 1: **Create a macro name.

**Step 2: **Define the variable as a string.

**Code:**

Sub OR_Example1() Dim i As String End Sub

**Step 3: **Now for this variable, we will assign the value through the OR logical test.

4.6 (247 ratings)

**Code:**

Sub OR_Example1() Dim i As String i = End Sub

**Step 4: **Our first logical test is **25 >20**.

**Code:**

Sub OR_Example1() Dim i As String i = 25 > 20 End Sub

**Step 5: **Now after the first logical test mention the word **OR** and enter the second logical test.

**Code:**

Sub OR_Example1() Dim i As String i = 25 > 20 Or 50 < 30 End Sub

**Step 6: **Ok, now VBA OR function tests whether the logical tests are TRUE or FALSE. Now assign the result of the variable to the VBA **message box**.

**Code:**

Sub OR_Example1() Dim i As String i = 25 > 20 Or 50 < 30 MsgBox i End Sub

**Step 7: **Run the macro and what the result is.

We got the result as TRUE because out of two logical tests we have provided one test is TRUE so the result is TRUE.

25 is greater than 20 and 50 is not less than 30, in this case, the first logical test is TRUE but second is FALSE. Because we have applied the VBA OR function, it needs any one of the condition to be TRUE to get the result as TRUE.

Now, look at the below code.

**Code:**

Sub OR_Example1() Dim i As String i = 25 = 20 Or 50 = 30 MsgBox i End Sub

I have changes the logical test equations from > and < to equal (=) sign. This will return FALSE as the result because 25 is not equal to 20 and 50 is not equal to 30.

#### VBA OR Function With IF Condition is Powerful

As I told OR can return either TRUE or FALSE as the result, but with the other logical function “IF”, we can manipulate results as per our needs.

Take the same logical tests from above, OR has returned only TRUE or FALSE but let’s combine this OR with IF.

**Step 1: **Before conducting any test open the function **IF**.

**Code:**

Sub OR_Example2() Dim i As String IF End Sub

**Step 2: **Now conduct tests using the **OR** function.

**Code:**

Sub OR_Example2() Dim i As String IF 25 = 20 Or 50 = 30 End Sub

**Step 3: **Put the word “Then” and write the result if the condition is TRUE, assign the value to the variable as **“Condition is Satisfied”**.

**Code:**

Sub OR_Example2() Dim i As String If 25 = 20 Or 50 = 30 Then i = "Condition is Satisfied" End Sub

**Step 4: **If the condition is FALSE then we need the different result, so put the word **“ELSE”** and in the next line assign the value to the variable “what should be the result if the condition or logical test is FALSE”.

**Code:**

Sub OR_Example2() Dim i As String If 25 = 20 Or 50 = 30 Then i = "Condition is Satisfied" Else i = "Condition is not Satisfied" End Sub

**Step 5:** End the IF function with the word **“End If”**.

**Code:**

Sub OR_Example2() Dim i As String If 25 = 20 Or 50 = 30 Then i = "Condition is Satisfied" Else i = "Condition is not Satisfied" End If End Sub

**Step 6: **Assign the value of the variable result to the **message box**.

**Code:**

Sub OR_Example2() Dim i As String If 25 = 20 Or 50 = 30 Then i = "Condition is Satisfied" Else i = "Condition is not Satisfied" End If MsgBox i End Sub

Run the macro, if the logical test is TRUE we will get the result as “Condition is Satisfied” or else we will get “Condition is not Satisfied”.

We got the result as **““Condition is not Satisfied”** because both the logical tests are FALSE.

Now I will change the logical tests.

**Code:**

Sub OR_Example2() Dim i As String If 25 > 20 Or 50 < 30 Then i = "Condition is Satisfied" Else i = "Condition is not Satisfied" End If MsgBox i End Sub

I will run the macro and see what the result is.

Like this, we can use one logical function with other logical function to arrive the results.

Solve the below case study to get used of logical functions.

#### Case Study to Solve

I have employee names and their respective departments.

If you have tried and not found the result then you can refer below code to understand the logic.

**Code:**

Sub Bonus_Calculation() Dim i As Long For i = 2 To 10 If Cells(i, 2).Value = "Finance" Or Cells(i, 2).Value = "IT" Then Cells(i, 3).Value = 5000 Else Cells(i, 3).Value = 1000 End If Next i End Sub

If the employee is from “Finance” or “IT” then they should get the bonus as “5000”. For other department employees bonus is “1000”.

Conduct the logical test and arrive the results.

### Recommended Articles

This has been a guide to VBA OR Function. Here we learn how to use OR Logical Operator in VBA along with some practical examples and downloadable excel template. Below are some useful excel articles related to VBA –

- VBA Boolean
- Data Type in VBA Excel
- Not Equal in VBA
- IFERROR in VBA
- VBA On Error
- VBA Code in Excel
- VBA UserForm
- VBA Match

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