I am writing values in an excel sheet using a MATLAB program. I am also writing values in cells using formulas (for e.g. the MATLAB program writes =AVERAGE(A1:A10) to a cell and this gets converted to appropriate value (i.e. when I open the sheet, I don’t see the above formula text, rather the value).
However I am having trouble writing array formulas (ones with curly braces around). Usually a user enters them by pressing Ctrl+Shift+Enter combination, curly braces appear and appropriate value is computed. However when I write these formulas enclosed in curly braces from MATLAB program the value is not computed, I simply see the formula text (with curly braces around it).
It seems I am not able to simulate Ctrl+Shift+Enter effect by simply writing the array formula to a cell.
Is there any solution to this?
Excel auto-converts values that start with
=into.formulas.To save an array formula, you need to write directly to the
FormulaArrayproperty of the range.More Details:
If you’re using a normal formula then you have two options in VBA. You can set the cell’s value or formula properties like this:
When using array formulas, you cant use either of these approaches, you need to store it into a different area of the cell:
When the user pushed Ctrl+Shift+Enter they are telling excel to send the
.valueof the cell into the .FormulaArraysection of the cell.Otherwise by default when excel sees the
=sign i assigns the.valueinto the.formulaAnyways, this is all relative the the excel object model even if it’s in VBA.
Now that I’ve gone into that detail I believe that matlab’s
xlswritefunction only writes to the value of cells, and cant write to this sub-property, I may be wrong.Something liek this may work in MATLAB (untested)