VBA & Macro Problems

How to Speed Up VBA Tests for Values in a List in Excel

Algirdas JasaitisAlgirdas Jasaitis Oct 26, 2026 869 views

Question details

The user needs an efficient way to check if values in a large dataset belong to a fixed list without writing formulas or checking cells one by one, which currently causes the macro to run very slowly.

How to Speed Up VBA Tests for Values in a List
Product
Excel / WPS Spreadsheet
Device & OS
not provided
Scenario
Running a VBA macro to validate or cross-reference thousands of rows of data against a fixed list of lookup values.
Observed behavior
Processing the dataset takes an excessively long time due to inefficient use of IF statements and writing formulas back to the worksheet cell by cell.
Before you start

Save a backup copy of your workbook before executing new VBA code, as macro operations that overwrite range data cannot be reversed using the standard Undo feature.

Solution 1Recommended

Use Memory Arrays and the Scripting.Dictionary Object

This method minimizes the slow interaction between VBA and the worksheet by reading all data into memory, checking values against a fast hash table, and writing the results back simultaneously.

Reading from and writing to worksheet cells individually is the primary cause of slow macro performance. By moving your dataset into an in-memory Array, you eliminate this bottleneck.

Combining an Array with a `Scripting.Dictionary` provides an ultra-fast way to check if an item exists in your fixed list, making it highly suitable for large datasets.

1
Initialize a Dictionary for the fixed list

Create a `Scripting.Dictionary` object using `CreateObject("Scripting.Dictionary")`. Loop through your fixed lookup list range and add each unique value as a dictionary key.

2
Load the target data into a Variant Array

Assign your target worksheet range directly to a Variant variable (e.g., `arrData = Range("A2:A100000").Value`). This instantly copies the entire range into memory.

3
Process the Array in memory

Set up a second Array of the exact same size to hold your output. Use a `For` loop to iterate through the data array. Use the `Dictionary.Exists(arrData(i, 1))` method to instantly verify if the value belongs to the fixed list, and store the result in your output array.

4
Write the results back in a single operation

Once the loop is complete, assign your output array back to the worksheet range (e.g., `Range("B2:B100000").Value = arrOutput`).

Use Memory Arrays and the Scripting.Dictionary Object
Massive Performance Gain: For 100,000+ rows, the Dictionary and Array method can reduce execution time from several minutes down to less than a second.
Execute VBA Macros Efficiently

Run Fast and Reliable VBA Macros with WPS Spreadsheet

WPS Office offers robust VBA support, allowing you to seamlessly execute advanced macro scripts, Dictionary objects, and Array operations. If you work with large datasets, WPS Spreadsheet processes your optimized VBA code rapidly while maintaining perfect format compatibility.

  1. 1. Open your workbook in WPS Spreadsheet: Launch WPS Office and open the .xlsm or .xlsb file containing your large dataset.
  2. 2. Access the VBA Editor: Navigate to the 'Developer' tab on the ribbon and click on 'Visual Basic', or press Alt + F11 to launch the macro editor.
  3. 3. Insert your optimized Array code: Insert a new Module, paste your Array and Dictionary optimization code, and press F5 to execute the fast lookup test.
Fully compatible with Microsoft Excel VBA syntax and macro objectsSupports advanced Array operations and Scripting.Dictionary for fast lookupsLightweight application footprint ensures smooth performance on massive datasetsFree and intuitive interface for coding, debugging, and executing macros
microsoft office alternative - wps office

Frequently Asked Questions

Why does writing formulas cell-by-cell slow down my VBA macro?

Every time VBA reads from or writes to a worksheet cell, it must cross the boundary between the VBA environment and the spreadsheet application. Doing this thousands of times inside a loop causes immense overhead, resulting in severe slowdowns. Arrays process data entirely within system memory.

Is using Application.WorksheetFunction.Match faster than a Dictionary?

While using the Match function in VBA is faster than a standard loop over cells, it is significantly slower than a Scripting.Dictionary when iterating over massive arrays. The Dictionary object uses hash tables, making value lookups nearly instantaneous regardless of the list size.

Do I need to enable specific references to use a Dictionary in VBA?

You can use 'Late Binding' by creating the object directly with `CreateObject("Scripting.Dictionary")` without enabling any references. However, if you prefer 'Early Binding' to utilize auto-complete features while writing code, you must enable the 'Microsoft Scripting Runtime' in the VBA Editor via Tools > References.