Monday, 13 October 2025

Excel VLOOKUP Function in VBA: A Simple Guide for Beginners

Do you like organizing data and finding answers quickly in Excel? 

There’s a magical function called VLOOKUP that helps you search for values in a table. Not only can you use it with formulas, but you can also use it in Excel VBA to make your work even smarter!

What is VLOOKUP?

VLOOKUP stands for Vertical Lookup. Imagine you have a big list of students with their marks, and you want to find the marks of a particular student. VLOOKUP helps you do this fast!

How Does VLOOKUP Work?

Let’s say you have this table:













Suppose you want to find the marks of Simran. Instead of searching line by line, VLOOKUP can do it in seconds!

VLOOKUP in Excel Formula Style

Here’s how the VLOOKUP formula looks:

=VLOOKUP("Simran", A2:C5, 3, FALSE)
  • "Simran" is the name you’re looking for.

  • A2:C5 is the table range.

  • 3 means you want the value from the 3rd column (Marks).

  • FALSE means you want an exact match.

Excel will return 90 for Simran.


Using VLOOKUP in Excel VBA

VBA (Visual Basic for Applications) allows you to write small programs in Excel.

Let’s write a simple code using VLOOKUP in VBA:


Sub FindMarks() Dim marks As Variant marks = Application.WorksheetFunction.VLookup("Simran", Range("A2:C5"), 3, False) MsgBox "Simran's marks are: " & marks End Sub

What does this code do?

  • Looks for "Simran" in the first column of your table (A2:C5).

  • Pulls the marks from the third column.

  • Shows a message box with the result: “Simran’s marks are: 90”


Why Learn VLOOKUP in VBA?

  • Faster Searches: Quickly find values in large lists.

  • Easy Automation: VBA can do search tasks automatically.

  • Fun Projects: You can create games, quizzes, or mark-checkers in Excel using VLOOKUP!


Try It Yourself

  1. Open Excel, and press ALT + F11 to open the VBA editor.

  2. Insert a new module.

  3. Copy and paste the code above.

  4. Click “Run” (green play button or press F5).

  5. You’ll see a pop-up with Simran’s marks!


Tips for Beginners

  • VLOOKUP always searches in the first column of your table.

  • Make sure the value you look up exists in your list!

  • Practice by changing names and numbers in the table.


Summary:
VLOOKUP is your helper for finding things in Excel, and with VBA, it becomes even more powerful. Try using it for your school projects, marksheet, or fun data games. Happy learning


No comments:

Post a Comment

Featured post

Pivot Tables

Pivot Tables are one of the most useful tool in excel, and most excel experts says that this tool is the magic tool for quickly prepar...