How do I return a range of cells as an output of an Excel Builder object in VBA function?

11 views (last 30 days)
I am trying to fill an Excel cell array with the output of a function defined in my Excel Builder Component. I know how to place the output of the function in a single cell. However, I do not know how to fill an array of cells.
For example:
If I have the function in VBA:
Function foo(x1 As Variant) As Variant
Dim aClass As Object
Dim y As Variant 'output
aClass = CreateObject("mycomponent.myclass.1_0")
Call aClass.foo(1,y,x1)
foo = y
End Function
In Excel, I would like to pass the following range of cells into this function:
A1:1
A2:2
A3:3
and have it output to the range:
B1:B3
This is simple to implement if I used a VBA subfunction.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 10 Sep 2012
You can return an array of cells from a MATLAB Excel Builder component by entering the formula as an array formula. This is accomplished by pressing CTRL+SHIFT+ENTER.
Select cells B1-B3, and enter the formula,
=foo(A1:A3)
Again to evaluate as an array formula, press CTRL+SHIFT+ENTER.
Consult the Excel documentation for more information on array formulas.

More Answers (0)

Categories

Find more on Data Export to MATLAB in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!