Getting the previous spill range of a dynamic array function

%3CLINGO-SUB%20id%3D%22lingo-sub-1270704%22%20slang%3D%22en-US%22%3EGetting%20the%20previous%20spill%20range%20of%20a%20dynamic%20array%20function%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1270704%22%20slang%3D%22en-US%22%3E%3CP%3EHi%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3Ewhen%20writing%20a%20worksheet%20function%20that%20returns%20an%20array%2C%20how%20can%20I%20get%20the%20spill%20range%20of%20the%20previous%20result%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIn%20a%20Function%2C%20Application.Caller.HasSpill%20and%20Application.Caller.SpillingToRange%20return%20False%20and%20Nothing%20respectively.%20Is%20this%20intentional%3F%20Is%20there%20another%20way%20to%20get%20the%20spill%20range%20(maybe%20using%20XLM%20or%20the%20C%20API%20instead)%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20need%20this%20for%20automatically%20formatting%20the%20result%20of%20a%20dynamic%20array%20function.%20With%20CSE%20array%20functions%20the%20Caller%20refers%20to%20the%20entire%20range.%20I%20schedule%20a%20function%20to%20run%20after%20Excel%20has%20finished%20calculating%20and%20apply%20formatting%20to%20the%20Caller%20range.%20By%20then%20it's%20possible%20to%20get%20the%20new%20spill%20range%2C%20but%20I%20also%20need%20to%20get%20the%20old%20one%20so%20that%20any%20previous%20formatting%20can%20be%20cleared%20before%20applying%20the%20new%20formatting%20(in%20the%20case%20where%20the%20spill%20range%20has%20shrunk).%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks%20in%20advance!%3C%2FP%3E%3CP%3ETony%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3Eps.%20I%20only%20need%20this%20to%20work%20on%20Windows%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1270704%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EExcel%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EFormulas%20and%20Functions%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EMacros%20and%20VBA%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1271053%22%20slang%3D%22en-US%22%3ERe%3A%20Getting%20the%20previous%20spill%20range%20of%20a%20dynamic%20array%20function%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1271053%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F604109%22%20target%3D%22_blank%22%3E%40pyxll%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EMy%20(not-yet-implemented)%20design%20for%20formatting%20dynamic%20arrays%20does%20this%20by%20storing%20the%20spill%20dimensions%20of%20the%20spill%20ref%20as%20cell%20metadata%20using%20the%20aftercalculate%20event.%3C%2FP%3E%3CP%3EThe%20cell%20metadata%20could%20be%20stored%20in%20various%20ways.%20To%20make%20it%20persist%20maybe%20define%20a%20Name%20for%20the%20spill%20ref%20and%20then%20use%20the%20Name%20as%20a%20key%20to%20an%20array%2Flist%2Fdictionary%2Fcollection%20thing%20that%20could%20be%20persisted%20as%20custom%20xml%20parts.%20Or%20for%20a%20non-persistent%20kludge%20use%20Cell.ID%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1271240%22%20slang%3D%22en-US%22%3ERe%3A%20Getting%20the%20previous%20spill%20range%20of%20a%20dynamic%20array%20function%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1271240%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F428214%22%20target%3D%22_blank%22%3E%40fastexcel%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHi%20Charles%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3Ethanks%20for%20that.%20Yeah%2C%20I%20was%20hoping%20to%20do%20it%20without%20having%20to%20add%20any%20metadata%20to%20the%20sheet.%20I%20already%20do%20that%20for%20some%20other%20features%20though%2C%20so%20it's%20not%20the%20end%20of%20the%20world.%20A%20map%20of%20cells%20to%20spill%20ranges%20in%20a%20CustomXMLPart%20is%20probably%20the%20least%20worst%20solution%20%3CLI-EMOJI%20id%3D%22lia_slightly-smiling-face%22%20title%3D%22%3Aslightly_smiling_face%3A%22%3E%3C%2FLI-EMOJI%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks%20again%2C%3C%2FP%3E%3CP%3ETony%3C%2FP%3E%3C%2FLINGO-BODY%3E
Highlighted
New Contributor

Hi,

 

when writing a worksheet function that returns an array, how can I get the spill range of the previous result?

 

In a Function, Application.Caller.HasSpill and Application.Caller.SpillingToRange return False and Nothing respectively. Is this intentional? Is there another way to get the spill range (maybe using XLM or the C API instead)?

 

I need this for automatically formatting the result of a dynamic array function. With CSE array functions the Caller refers to the entire range. I schedule a function to run after Excel has finished calculating and apply formatting to the Caller range. By then it's possible to get the new spill range, but I also need to get the old one so that any previous formatting can be cleared before applying the new formatting (in the case where the spill range has shrunk).

 

Thanks in advance!

Tony

 

ps. I only need this to work on Windows

2 Replies
Highlighted

@pyxll 

 

My (not-yet-implemented) design for formatting dynamic arrays does this by storing the spill dimensions of the spill ref as cell metadata using the aftercalculate event.

The cell metadata could be stored in various ways. To make it persist maybe define a Name for the spill ref and then use the Name as a key to an array/list/dictionary/collection thing that could be persisted as custom xml parts. Or for a non-persistent kludge use Cell.ID

Highlighted

@fastexcel 

 

Hi Charles,

 

thanks for that. Yeah, I was hoping to do it without having to add any metadata to the sheet. I already do that for some other features though, so it's not the end of the world. A map of cells to spill ranges in a CustomXMLPart is probably the least worst solution

 

Thanks again,

Tony