Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Excel Tutorial
  • Excel Formulas
  • Excel Shortcut Keys
  • Data Analysis in Excel
  • Formatting in Excel
  • Excel Workbooks
  • Statistical Functions
  • Data Visualization in Excel
  • Pivot Tables in Excel
  • MS Excel Quiz
  • Excel Interview Questions
  • Advance Excel
Open In App
Next Article:
VBA Find Function in Excel
Next article icon

VBA Find Function in Excel

Last Updated : 08 Dec, 2023
Comments
Improve
Suggest changes
Like Article
Like
Report

In an Excel sheet subset of cells represents the VBA Range which can be single cells or multiple cells. The find function will help to modify our search within its Range object. A specific value in the given range of cells is to search with the help of the Find function. Excel VBA provides different parameters in the Find function so that we can search according to the search order or direction and also we can make a case-sensitive search which will be discussed further in this article.

Excel VBA Find Function

As we know about the Find Function in Excel, we can use the Shortcut key "Ctrl+F" to find the content that you are looking for. The FIND function of VBA searches for a specified value in the range that is defined by the user. A VBA code is written by entering arguments of the FIND function.

Below is the syntax given for using the find function in VBA,

Syntax: Find(What, [After], [LookIn], [LookAt], [SearchOrder], [SearchDirection AsXlSearchDirection = xlNext], [MatchCase], [MatchByte], [SearchFormat]) As Range

Parameter

Required

Description

WhatRequiredThe value for which we are searching
AfterOptionalRange of cells from where the search will start
LookinOptionalFunction search in value, formulas, and comment
LookAtOptionalWe can search in two ways one to search in a part of the string in a cell or to match the entire cell
SearchOrderOptionalIt can search in the cells row-wise, column-wise, or by the method
SearchDirectionOptionalWe can mention whether to search forward or backward in the sheet
MatchCaseOptionalCase Sensitive should be considered or not should be mentioned by True or False
MatchByte OptionalIt can be used if we have used double - byte then we can assign True to match double-byte characters with double-byte only and false to match the double-byte characters with single-byte only
SearchFormatOptionalThe search format

How to Use the VBA Find Function in Excel Example

Use the Find Function without Parameter

Below are some Examples of VBA Find Function:

How to Use the Find Function without Parameter

Let's take a sample of data. Below is the dataset given:

Sample-data

The following code is to find the name Niladri from cell A1 to A5 and the find function will return A3 in output which is the address of the cell.

Finding-cell-number-for-niladri

1. Using After 

In this example, we are instructing the compiler to search for "Utsav" after cell A3.

Using-after-to-find-cell-address

2. Using LookIn 

LookIn function search in value, formulas, and comment.

value: It searches for the complete value in the cell if we are searching for "orange" then the ranged cell should contain the complete value "orange".

formulas: It searches for the value which can be generated by any formula or function like left("orange",4)  will return or if it is present in any one of the ranged cells then it will return the address of that cell.

comment: It that whether the searched value contains in the comment box or not.

Let's take a sample of data,

Data-sample

Code with three different parameters of LookIn.

Three-different-parameters-of-lookin

3. Using LookAt

In this function, we have two parameters one is xlWhole and xlPart.

xlWhole: Searched value should be in the entire range.

xlPart: Searched value should have to match with a part of the cell.

Let's take a sample of data,

Data-sample

Code to search the word "Tube" in the whole part of the cell.

Searching-tube-in-cell

Code to search the word "Tube" in some part of the cell.

Code-to-search-word-in-cell

4. Using SearchOrder

With the help of this function, we can tell VBA to search according to row or column. Let's take a sample of the data.

Data-sample

Code to search "Ayush" row-wise and column-wise.

Searching-row-wise-and-column-wise

5. Using SearchDirection

With the help of this function, we can tell VBA to search forward or backward, like if we want to search in A1:A5 and we are using xlNext then VBA will search in the following order ⇢ A1, A2, A3, A4, A5. If we are using xlPrevious then VBA will search in the following order ⇢ A5, A4, A3, A2, A1. Let's take a sample of data:

Data-sample

To Search "Ayush" using xlNext the code will return A4 and by using xlPrevious it will return A6.

Searching-ayush-name

6. Using MatchCase

This function tells VBA whether to be case sensitive (i.e. to differentiate between capital letters and small letters) or not if MatchCase is true then VBA will consider case sensitivity and if it is false then it will not consider case sensitivity. Let's take a sample of data:

Data-sample

If we want to search for "Ayush" and MatchCase is true then it will return A6 and if MatchCase is false then it will return A4.

Searching-ayush-name

7. Using WildCard

The "*" symbol is used to represent more than one character. For example, "A*" VBA will search for a word that starts with A, "*a" VBA will search for a word that ends with a. Let's take a sample of data:

Data-sample

The following code is to search for A1 and A2,

Searching-for-A1-and-A2

How to use the VBA Find Function in Excel?

Open the Visual Basic for Application editor in Excel. Then, you can write the VBA code using the 'Find' method to search for the desired data. Specify the Search parameters such as the value to find, the range to search within, and other optional settings like case sensitivity and search direction.

Is the VBA Find Function case-sensitive by default?

No, the VBA Find Function is not case-sensitive by default. You can make it case-sensitive by setting the 'MatchCase' parameter to 'True'.


Next Article
VBA Find Function in Excel

A

ayushdey110
Improve
Article Tags :
  • Excel
  • Excel-VBA
  • ExcelGuide

Similar Reads

    Excel VBA | sum() functions
    Visual Basic for Applications (VBA) is the programming language of Excel and other offices. It is an event-driven programming language from Microsoft. With Excel VBA one can automate many tasks in excel and all other office software. It helps in generating reports, preparing various charts, graphs a
    2 min read
    Function and Sub in Excel VBA
    In Visual Basic, the functions and sub-procedures play similar roles but have different or unique characteristics. However, both perform a programmed task. They utilize a set or group of commands to deliver the required results. The key difference between the sub and the functions is that a sub-proc
    4 min read
    InputBox Function in Excel VBA
    Input Box is one of the most frequently used functions in VBA Macro. The dialogue box that appears asks for input from the user and returns a constant/code/number/text. For example, if you want to create a log-in form in VBA, you will require an input box function. Let's learn how to create an input
    11 min read
    Excel IF Function
    The IF function in Excel is one of the most powerful and commonly used formulas that allows you to perform logical tests and return different values based on whether the condition is true or false. If you’ve ever needed to check whether a value meets certain criteria, then the IF function is the too
    12 min read
    Find() function in MATLAB
    The find() function in MATLAB is used to find the indices and values of non-zero elements or the elements which satisfy a given condition. The relational expression can be used in conjunction with find to find the indices of elements that meet the given condition. It returns a vector that contains t
    3 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences