Resized array show #NA

I have the following function
=INDIRECT((CONCATENATE("‘file:" , $Constants.B3 , "’#$Masterlist_2025.",$Constants.B1,":",$Constants.B2)))

which works. I made the file and boundaries variables as the source comes from another person and needs to be a bit flexible.

The problem I’m having is that if I change B2 to a smaller value the cells that are now outside the scope of the new boundary show as #NA. Likewise when add rows or columns (changing B2) they don’t show up. It seems that the original size is fixed. Any way to change that?

I would suppose you are talking of a formula with array output (entered with Ctrl+Shift+Enter). This post is useless and will be removed if you tell that’s not the case.
In this case the issue is that the output range is locked on first execution of the formula. If something is changed by arguments what influences the functionally wanted size of the output range there are issues (overflow, underflow, flooding).

I suppose you did not resize the output range, but references to input ranges.
This is hard to handle with the current concept of array formula output.
However, it’s also hard to give an answer based on a complicated abstract example not applied to an example document.

This isn’t actually a solution to your specific problem, but a help to understand it better.
Hoping you can understand my way of giving a concrete example: See attachment.

disask_127512_.ods (16.7 KB)

Hello, Wolfgang!
Yes, indeed, the problem is that the output array size for an array formula is calculated when the formula is entered and doesn’t change.
See bug tdf#127808 and @Regina 's comment 2 there.
Until this bug is fixed, a workaround can be suggested: use a macro to recalculate the array formulas, determining the new size.
An example of a macro that re-enters an array formula is below.
Create a new document and run macro TestSetArrayFormula several times.
As a next step, it might be possible to write a macro that finds all array formulas in a document and recalculates them using the macro below.

' lang:en
' Assigns an array formula to a cell (as with interactive input).
' The specified formula is entered into the cells of the range, the size of which corresponds to
' the size of the array returned by the formula.
' Parameters:
' oRange         cell that specifies the upper left corner of the target range.
' arrayFormula   array formula (without {...}.
'
' The function returns the resulting range of cells or Nothing.
Function SetArrayFormula(ByVal oRange As Object, ByVal arrayFormula As String) As Object
  Dim oDoc as Object, oController As Object, oCur as Object, oDisp as Object
  Dim props(0) as new com.sun.star.beans.PropertyValue
  Dim selection_old, arr, oCell As Object, localFormula As String
  
  oDoc=oRange.Spreadsheet.DrawPage.Forms.Parent
  oController=oDoc.CurrentController
  selection_old = oController.Selection
  
  oCell=oRange.getCellByPosition(0,0)
  
  If oCell.getArrayFormula()<>"" Then
    oCur=oCell.SpreadSheet.CreateCursorByRange(oCell)
    oCur.CollapseToCurrentArray()
    oCur.setArrayFormula ""
  End If  
  
  ' get local formula
  oCell.setFormula IIf(Left(arrayFormula, 1)="=", "", "=") & arrayformula
  localFormula=oCell.FormulaLocal
    
  oDisp=createUnoService("com.sun.star.frame.DispatchHelper")
  
  props(0).Name = "ToPoint"
  arr=Split(oCell.AbsoluteName, ".")
  props(0).Value = arr(Ubound(arr))
  oDisp.executeDispatch oController.Frame, ".uno:GoToCell", "", 0, props
  
  props(0).Name = "Formula"
  props(0).Value = localFormula
  oDisp.executeDispatch oController.Frame, ".uno:InsertMatrix", "", 0, props
     
  oCur=oCell.SpreadSheet.CreateCursorByRange(oCell)
  oCur.CollapseToCurrentArray()
  SetArrayFormula=oCur 
  
  On Error Resume Next
  oController.Select selection_old
End Function

Sub TestSetArrayFormula()
  Dim oCell As Object, oRange As Object, s As String, s2 As String, formula As String
  oCell = ThisComponent.Sheets(0).GetCellByPosition(0, 0)  
  s = "Hello, World!!"
  s2 = IIf(Instr(1, oCell.Formula, "!!") = 0, s, Left(s, Len(s) - 1))
  formula="Mid(""" & s2 & """; Row(A1:A" & Len(s2) & ");1)"
  oRange=SetArrayFormula(oCell, formula)
  Msgbox "Array Formula Range: " & oRange.AbsoluteName
End Sub
1 Like

You may know that I am listed CC for that “bug” which actually is a feature request, and that I rarely understand something concerning Excel.
You surely know that I have a working solution based on user code for my own use which I, however, can’t recommend to an “ordinary user”. It would require to rtfm explaining pages (sheets) at least.
(You may even have read Request for comments concerning a package of routines made to avoid locked ranges and related issues . The example there only covers a very special case, of course.)

Concerning your suggestion I’m sceptical. At least the “redimensioning” macro would need to check if the new output range is “free”.

I would stil prefer a “bridge” over the gap between the “formula world” of Calc and “procedural programming” which I implemented giving a way to create named variables (mostly hosting arrays) by formulas and to acces them as a whole or elementwise.

Yes, that is the problem. Sorry I couldn’t post the actuall sheets as they contain personal information. thanks

I’ll take a look at the macro. I’ve never done a calc macro (& only limited excel macros) .
I did find a bit of a hack / solution. I can just recreate when needed. I don’t expect a lot of changes.
ctrl+/
F2
ctrl+a / copy
then
ctrl+/
del
paste the copied formula (with the braces)

There is a stupid extension that I created.