Master Excel VBA VLOOKUP in Another Workbook Practical Example Guide

Bobby Jul 13, 2026

VBA, or Visual Basic for Applications, is a programming language built into the Microsoft Excel application, allowing users to automate tasks, analyze data, and build complex functionality. One of the most powerful tools in VBA is the Vlookup function, which retrieves data from another table or range based on a unique identifier. Today, we'll explore how to use Vlookup in another workbook with accurate examples to enhance your Excel skills.

Excel VBA Copy Data from Multiple Workbooks
Excel VBA Copy Data from Multiple Workbooks

Before diving in, ensure you have the necessary setup: two workbooks open - one for your data and one for running your VBA. Let's start by understanding the key components

Master Excel VBA with Professional Tips and Best Practices
Master Excel VBA with Professional Tips and Best Practices

Understanding Your Workbooks and Ranges

To use Vlookup from one workbook to another, you must be familiar with your workbooks' structures and the ranges in which your data resides.

Excel Dependent Drop Down List VLOOKUP | MyExcelOnline
Excel Dependent Drop Down List VLOOKUP | MyExcelOnline

Let's assume you have two workbooks - Main_WB.xlsx (our source) and VBA_WB.xlsx (our destination); with respective sheets - SourceData and DestData. In SourceData, columns A:B have data (ID & Name), and DestData has columns A:B where you want to paste the data.

Setting Up and Running Your VBA

Free Excel VBA Book
Free Excel VBA Book

With your workbooks open, press Alt + F11 to open the VBA editor. Under DestData, insert a new module (Insert > Module).

Defining the VBA_WBWorkbook Object

First, set up your VBA_WB as an object for easy access. Add the following line at the top of your module:

VBA for Excel Cheat Sheet
VBA for Excel Cheat Sheet

```vba Dim VBA_WB As Workbook Set VBA_WB = ThisWorkbook ```

This sets the active workbook (VBA_WB.xlsx) as the 'VBA_WB' object, making it accessible throughout your code.

Implementing the Vlookup Function with VBA

Now, construct your Vlookup function. We'll use a loop to paste the data from SourceData to DestData. Add the following subroutine to your module:

How to vlookup excel (Step by step) - How To Do Topics
How to vlookup excel (Step by step) - How To Do Topics

```vba Sub VlookupAnotherWorkbook() Dim IDCol As Range Dim DestCell As Range Dim NameCell As Range ' Set source data range Set IDCol = VBA_WB.Worksheets("SourceData").Range("A2:A" & VBA_WB.Worksheets("SourceData").Cells(Rows.Count, "A").End(xlUp).Row) ' Loop through each ID in DestData For Each DestCell In ThisWorkbook.Worksheets("DestData").Range("A2:A" & ThisWorkbook.Worksheets("DestData").Cells(Rows.Count, "A").End(xlUp).Row) ' Find ID in SourceData Set NameCell = VBA_WB.Worksheets("SourceData").Range("B2:B" & VBA_WB.Worksheets("SourceData").Cells(Rows.Count, "B").End(xlUp).Row).Find(what:=DestCell.Value, LookIn:=xlValues, LookAt:=xlWhole) ' If ID not found, exit If NameCell Is Nothing Then Exit For ' If found, paste the name in DestData DestCell.Offset(0, 1).Value = NameCell.Offset(0, 1).Value Next DestCell End Sub ```

This subroutine looks up IDs in DestData and, if found in SourceData, pastes the corresponding Name. Run the subroutine (VlookupAnotherWorkbook) using the Run > Run Sub/UserForm menu.

Now, explore and refine this code to meet your specific use cases. By understanding and deploying VBA with Vlookup across workbooks, you can streamline complex tasks and boost your productivity!

How to Do a VLOOKUP in an Excel Spreadsheet
How to Do a VLOOKUP in an Excel Spreadsheet
the only guide you need to know about excel vlookup, by peter j schreck
the only guide you need to know about excel vlookup, by peter j schreck
How to VLOOKUP in 30 seconds
How to VLOOKUP in 30 seconds
VBA Copy Sheet to New/Existing Workbook
VBA Copy Sheet to New/Existing Workbook
VBA to Create PDF from Excel Sheet & Email It With Outlook
VBA to Create PDF from Excel Sheet & Email It With Outlook
Vlookup
Vlookup
What You Can Do with VBA (6 Practical Uses)
What You Can Do with VBA (6 Practical Uses)
How to Use VLOOKUP in Excel
How to Use VLOOKUP in Excel
Excel VBA UserForm with Navigation Buttons 🚀 | See it in Action! #shorts
Excel VBA UserForm with Navigation Buttons 🚀 | See it in Action! #shorts