How to Reference a FILTER Spill Range in Excel VBA
Question details
The user needs to reference the dynamic array results of a FILTER function within an Excel VBA macro.

- Product
- Microsoft Excel
- Device & OS
- not provided
- Scenario
- Writing an Excel VBA macro that interacts with data dynamically generated by a FILTER formula.
- Observed behavior
- Standard Range object references fail or return errors because the FILTER formula outputs a spilled dynamic array rather than a conventional Range object.
Ensure you are using a version of Excel that supports dynamic arrays (Office 365 or Excel 2021 and newer) and identify the specific anchor cell where your FILTER formula is located.
Use the Spill-Range Operator (#) with a Variant Variable
The most reliable way to capture a dynamic spilled array in VBA is by appending the hash symbol (#) to the starting cell reference and assigning it directly to a Variant variable.
Dynamic array functions like FILTER populate multiple cells automatically, creating a 'spill range'. In VBA, attempting to set this result as a standard Range object often causes type mismatch errors because the result is evaluated as an array. Using the spill operator (#) tells VBA to grab the entire spilled array dynamically, no matter how its size changes.
Open the VBA Editor (ALT + F11) and declare a variable to hold the array data by typing: Dim V As Variant
Locate the top-left cell where the =FILTER() formula was entered in your worksheet (for example, cell C1).
Assign the dynamic array to your variable by appending the # symbol to the cell reference: V = Range("C1#").
If the anchor cell C1 is defined with a custom name in the Name Manager (e.g., 'Flt'), you can alternatively reference it using: V = Range("Flt#").

Try WPS Office for Advanced Spreadsheet Management
If you frequently work with complex formulas, dynamic arrays, and macros, WPS Office provides a lightweight, highly compatible, and free alternative to Microsoft Office. It seamlessly opens your Excel workbooks, handles advanced functions, and offers an intuitive interface without heavy subscription fees.
- 1. Download WPS Office: Get the free installer from the official WPS website and complete the quick installation process.
- 2. Open your Excel file: Launch WPS Spreadsheet and open your existing .xlsx or .xlsm files directly without any format conversion.
- 3. Work with your data: Continue using your standard formulas, dynamic arrays, and macros seamlessly in a familiar, user-friendly interface.

Frequently Asked Questions
Why do I get a Type Mismatch error when setting a spilled range in VBA?
A Type Mismatch error occurs because dynamic array functions return an array of values, not a standard Range object. To fix this, declare your VBA variable as a Variant and assign it using the spill operator (#) instead of using the 'Set' keyword.
Can I use the spill operator (#) in older versions of Excel?
No, the spill operator and dynamic arrays are exclusive features introduced in Excel 365 and Excel 2021. Older versions rely on legacy Ctrl+Shift+Enter (CSE) array formulas, which do not support the # reference syntax in VBA.
How do I loop through the spill range array once it is assigned to a Variant in VBA?
Once you assign the spilled range to a Variant (e.g., V = Range("C1#")), you can use a standard For loop. Iterate through the rows using For i = LBound(V, 1) To UBound(V, 1), and through the columns using LBound(V, 2) To UBound(V, 2).
Does WPS Spreadsheet support dynamic array formulas like FILTER?
Yes, modern versions of WPS Spreadsheet are equipped to handle dynamic array formulas. You can utilize functions like FILTER, SORT, and UNIQUE exactly as you would in Microsoft Excel.




