Nov 20 2022 03:31 AM
Just as a heads-up to fellow Excel programmers. SPILLs (via FILTER) are obviously a great technique to import data from external databases. The syntax to reference the imported results in eg A100:Y103 is the very handy "A100#". All of this works very well in the presence of these databases.
When we periodically supply outside parties with our production Excels, we do not export these databases (because in my experience we end up spending countless hours supporting the recipient in staging our production environment on their system). To facilitate the data exchange, we only supply standalone versions of those Excels, ie only workbooks with broken links.
Now, here the nub: When you break the link to the data source, Excel will freeze the imported results in A100:Y103 *) That is exactly what we want. So far, so good.
BUT ...
The reference "A100#" now produces a #REF! error because that range is no longer a SPILL (but an ordinary range of numbers in the sheet). To my money, this is an oversight by Microsoft. Break Links would need to replace all references to "A100#" with the fixed span "A100:Y103".
To work around this issue, I put aside an oversized fixed span eg A100:BA103. To the right of that span in BB100:BB103, I put some text (instructions on what to do with #SPILL errors). I then put the FILTER call, as before, in A100. But instead of referencing A100#, I now reference the fixed span A100:BA103, providing code (IFs) to deal with blank cells.
So long as the imported data can fit into the fixed span, all is well. If FILTER spills over the end of the fixed span, the text to the right of it forces a #SPILL error, therefore preventing accidents.
*) If you are lucky, that is! Data/Edit Links/Break Links is arguably the most unreliable feature in Excel and we use a VBA macro to largely replace this functionality, but that's a matter for a separate post.
Aug 23 2024 08:28 AM - edited Aug 23 2024 09:30 AM
The OP merits a follow-up. During the summer of 2024, an idea came to me how to fix the breaking spills problem in VBA. I then faced the question whether to continue with the work-around described in the OP or to rephrase my code. I want to share here why that was even a question. Let's start by recalling the pros and cons of spilling into a fixed range:
Pros:
Cons:
At which point the question pops up "What's the alternative?" And one possible reason for staying with the work-around above is that you might reject them all...
How to slice a spill?
At the heart of this question is the impossibility in Excel to return a range of Spills. It is simply not possible to split a 6xN spill into 6 spills of 1xN each. It is hence not possible to easily reference the 2nd row of a spill out for D400 as D401#.
Put that question to ChatGBT and it will tell you to use INDEX(s#,r,0) to access row r in spill s. This is true enough, so let's review the pros and cons of this approach:
Pros:
Cons:
I did not like this answer one little bit and set about writing a Lambda to ease my existence. I was very pleased with my final version, which read
=WithRows(s#, RowLabels, LAMBDA(r, FILTER(r("Cash"), r("Dates")< ...
All my spill rows are prefixed by user-friendly labels such that RowLabels was simply the column immediately in front of the spill data.
Pros:
Cons:
I discarded the ideas of INDEX and WithRows when I recalled the arcane Excel intersection operator: It is possible to address D6 by writing "=D:D 6:6." D:D addresses the entire column D, 6:6 the entire row 6. The space in between is the "intersection operator" - Excel will only address those cells which are spanned by the range before it and after. In this instance, that is only D6.
In 30 years of programming Excel, I never once had the occasion to use it. I have now embraced it to slice my spills. The reference
=$D400# 401:401
will return the 2nd row from the range spilling out of D400.
Pros:
Cons:
If I managed to sustain your attention until this point, then I shall reward you with a further thought. You may recall bullet #2 from the Pros of the work-around: How can we construct a spill from manual inputs such that it becomes possible to feed a downstream calculation that uses spill notation?
I wrote a VBA macro to perform this procedure in the spill area itself: Write your input data somewhere, say into B100:AZ105. Put a reference to that fixed range into the TLC of your spill area, ie =B100:AZ105. (The data will spill, obviously.) Now press F2 followed by F9, then Enter. You can now delete B100:AZ105 😉
Happy coding.