Array Formulas in VBA
I've never used dynamic arrays in VBA and I guess I'm overlooking something
simple. When I do it as you've described it compiles and runs without
error. But I have no way to look at the result that's presumably in the
Matrix(..) array. Whatever I do to look at the result gives me a "Type
mismatch" error. I can't even ask it what size the array is with UBound or
I get the same error.
So I went to Walkenbach's book to look up dynamic arrays. He seems to say
one has to ReDim the array to put actual bounds on it before you can use it.
So blundering ahead, after the EVALUATE statement I tried:
ReDim Preserve Matrix(10,10)
but that also just gives a "Type Mismatch" error. I'm missing something
elementary here...
Bill
---------------------------------
"Bob Phillips" wrote in message
...
Don't dimension the array, let evaluate do it dynamically
dim Matrix
Matrix = Evaluate(....)
--
HTH
Bob Phillips
(remove nothere from email address if mailing direct)
"Bill Martin" wrote in message
...
Pardon my denseness, but I don't see where the result of the MMULT
operation
ends up. Sticking your code into a toy test module it will compile and
execute without complaint, but I don't see where to find the result.
I tried using:
dim Matrix(100,100)
Matrix = Evaluate(....)
... but that fails with an error message "Can't assign to array". Where
do
I find the result using your method?
Thanks.
Bill
------------------------------------
"Bob Phillips" wrote in message
...
Try evaluating it
Evaluate("MMULT(D6:D105,TRANSPOSE(Sheet2!E3:P3))")
--
HTH
Bob Phillips
(remove nothere from email address if mailing direct)
"Bill Martin" wrote in message
...
Is there some way to use an array formula within VBA? For example, I
find
that I can use a MMULT array formula in VBA with the result posted to
a
spreadsheet by using:
Range("AD6:AD105").Select
Selection.FormulaArray = "=MMULT(D6:D105,TRANSPOSE(Sheet2!E3:P3))"
But it would be much better for me if I could put the resulting vector
directly into a VBA array for use rather than back out onto the
spreadsheet.
I can do this with scalar functions that take an array input and
produce
a
single result such as:
dim Vector(10) as single
... fill the vector ...
X = WorksheetFunction.Max(Vector)
I haven't been able to figure out how to do the analogous thing with
built
in worksheet array functions though.
Thanks.
Bill
|