Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi. If you don't want a single array with two dimensions, perhaps a
workaround... Sub Demo() Dim v '// A 3 x 1 Matrix... v = [MMULT(A1:C3,E1:E3)] '// A 3 Element vector... v = WorksheetFunction.Transpose(v) '// Or perhaps all at once... v = [Transpose(MMULT(A1:C3,E1:E3))] End Sub -- HTH. :) Dana DeLouis Windows XP, Office 2003 "Bill Martin" wrote in message ... Ok -- I can make it work. There's a nasty quirk to it though that I don't understand which of course is why I had so much trouble with it. By random chance, the problem that I was working was to multiply a rectangular matrix by a vector, producing a vector result with 6 elements. (And I did have the dimensions and transposing and all correct, though thanks for suggesting it Dana.) The thing is that after the Matrix = Evaluate(...) function I would go in and look for an element of the six element vector that should have been generated. For example I would look for the third element as Matrix(3) and would get the error. For reasons I don't quite understand though, I noticed in the Locals debug window that Matrix(3) for example could be expanded and it truly is named Matrix (3,1). The one dimensional result vector is sitting in a two dimensional array, but with only the first dimension used -- if you can follow that explanation. Anyhow, if I address the result vector as a two dimensional array, with the second dimension always =1 then I'm in high clover. Now hopefully I can get this approach to work in my complex and wonderful problem as well as it does in my toy example. To complete the experiment I also changed my arrays around so it would produce a 2x6 array as an answer. In that case VBA generated a 2x6 array for an answer just as one would hope. Only the 1 dimensional vector seems to produce the weird case with an extra dimension. Thanks folks. Bill ------------------------------------ "Bob Phillips" wrote in message ... Bill, I used this and it worked Dim xyz xyz = Evaluate("MMULT(A13:A15,A13:C13)") Debug.Print LBound(xyz), xyz(1, 3) Note Dana's comments about array sizes. -- HTH Bob Phillips (remove nothere from email address if mailing direct) "Bill Martin" wrote in message ... 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 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Convert Array Formulas to Regular Formulas | Excel Worksheet Functions | |||
Convert Array Formulas to Regular Formulas | Excel Worksheet Functions | |||
array formulas | Excel Discussion (Misc queries) | |||
Array formulas | Excel Worksheet Functions |