Forum Discussion
INDEXLS to index Linked Spills in foreign Workbooks
I had a further thought.
I was overthinking the calculation tree. On reflection, one feature of Spills is that their elements are either ALL dirty or ALL clean. It cannot be, as I worried in the OP, that only r(1,4) is dirty. If the source Workbook refreshes r(1,4), then importSpill will fire and the entire range spilling out of TLC will be dirty, including TLC - hence assuring that INDEXLS would fire.
Moreover, rather than reinvent INDEX, I can simply re-imagine the "#" (as a UDF called "LS"):
Public Function LS(TLC As Range) As Variant
On Error GoTo BAIL_OUT
' This function should only be called when r references a Spill created by importSpill
' from a link to another Workbook. TLC must reference r(1,1) of that data range (but
' NOT feature a trailing "#"). If a range spills out of TLC, LS will simply refer
' to it (as if TLC had been supplied with a trailing "#"). But if the linked input to
' importSpill was broken (and the Spill replaced with a range of values), LS will
' find the BRC of the data from the Note importSpill affixed to the TLC.
If TLC.HasSpill Then
LS = TLC.SpillingToRange
Else
Dim crumbs As Variant
crumbs = Split(TLC.Comment.Text, "x")
Dim BRC As Range
Set BRC = TLC.Worksheet.Cells( _
TLC.Row + crumbs(0) - 1, _
TLC.Column + crumbs(1) - 1 _
)
LS = Range(TLC, BRC)
End If
Exit Function
BAIL_OUT:
LS = CVErr(xlErrNA)
End Function
We can now simply write
=VLOOKUP(someValue,LS(AA100),2,FALSE)
which is rather satisfyingly concise. Similarly, if we wanted to index that Spill,
=INDEX(LS(AA100),1,4)
will do that.
The processing overheads in the production sheet (with the live links) are miniscule since the UDF instantly returns the available Spill. The overheads of processing the breadcrumbs inside the Note only fall to the frozen copy of the Workbook, which seems acceptable to me.
PS: Contrasting the response of ChatGBT to NikolinoDE to the evolution of my (human) thinking across this thread is fascinating. A truly intelligent response to my OP would have read "Don't be so blooming stupid. Consider that instead of writing INDEXLS, you could just write LS far more easily and plug it into the standard INDEX function."