SOLVED

How do I access #SPILL area from FILTER() result in VBA?

%3CLINGO-SUB%20id%3D%22lingo-sub-3242937%22%20slang%3D%22en-US%22%3EHow%20do%20I%20access%20%23SPILL%20area%20from%20FILTER()%20result%20in%20VBA%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3242937%22%20slang%3D%22en-US%22%3E%3CP%3EIf%20I%20use%26nbsp%3B%3CSTRONG%3EFILTER()%3C%2FSTRONG%3E%20function%20cell%20%24B%241%2C%20how%20do%20I%20target%20or%20select%20the%20entire%20spill%20range%20from%20VBA%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThere%20is%20a%20range%20or%20table.%20It%20is%20outlined%20in%20blue.%20The%20blue%20outline%20updates%20dynamically%20with%20the%20number%20of%20lines%20returned%20as%20the%20%3CSTRONG%3EFILTER()%3C%2FSTRONG%3E%20arguments%20are%20changed.%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThere%20is%20no%20explicit%20variable%20in%20the%20%3CU%3EName%20Manager%3C%2FU%3E%20(as%20happens%20when%20tables%20and%20print%20areas%20are%20defined%2C%20for%20example).%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIn%20the%20docs.microsoft.com%20Office%20VBA%20references%2C%20there%20are%20the%20%3CSTRONG%3EFILTER%3C%2FSTRONG%3E%20and%20%3CSTRONG%3EFILTERS%3C%2FSTRONG%3E%20objects.%20Both%20then%20refer%20to%20%3CSTRONG%3EAUTOFILTER%3C%2FSTRONG%3E%3CSPAN%3E%2C%20so%20I%20am%20unsure%20if%20this%20will%20also%20apply%20to%20the%20results%20generated%20by%20%3CSTRONG%3EFILTER()%3C%2FSTRONG%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3EAre%20there%20any%20ideas%20or%20suggestions%3F%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-3242937%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EExcel%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EFormulas%20and%20Functions%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-3243070%22%20slang%3D%22en-US%22%3ERe%3A%20How%20do%20I%20access%20%23SPILL%20area%20from%20FILTER()%20result%20in%20VBA%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3243070%22%20slang%3D%22en-US%22%3EUse%20the%20%23%20character%2C%20so%20%24B%241%23%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-3243082%22%20slang%3D%22en-US%22%3ERe%3A%20How%20do%20I%20access%20%23SPILL%20area%20from%20FILTER()%20result%20in%20VBA%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3243082%22%20slang%3D%22en-US%22%3EI%20know%20that%20works%20the%20cells%2C%20but%20I%20didn't%20know%20I%20can%20use%20that%20in%20VBA%3C%2FLINGO-BODY%3E
New Contributor

If I use FILTER() function cell $B$1, how do I target or select the entire spill range from VBA?

 

There is a range or table. It is outlined in blue. The blue outline updates dynamically with the number of lines returned as the FILTER() arguments are changed. 

 

There is no explicit variable in the Name Manager (as happens when tables and print areas are defined, for example).

 

In the docs.microsoft.com Office VBA references, there are the FILTER and FILTERS objects. Both then refer to AUTOFILTER, so I am unsure if this will also apply to the results generated by FILTER()

 

Are there any ideas or suggestions?

6 Replies
best response confirmed by GregGann (New Contributor)
Solution
Use the # character, so $B$1#
I know that works the cells, but I didn't know I can use that in VBA
I tested it and it worked for me. For example I did this in the Immediate window where D1 has a spill function:
print activesheet.range("d1#").rows.count
and got 12

@mtarler 

 

I am having better success than I hope for. Thanks

 

Range("B6:Q6").Select
Selection.Copy
Range("B6#").Select
Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, SkipBlanks:=False, Transpose:=False

,

 

FYI, it is much slower if you .select for everything. You can and should just
Range([source]).copy ([Destination])
also I found but didn't play with or test, Range has a couple interesting properties:
SpillingToRange and SpillParent
might be interesting to check them out
I believe there is also a HasSpill property that you can test, as attempting to reference a non-existent spill range using spilltorange will generate a run time error (not sure if the Range("B6#") reference will throw an error if there's no spill range).