Operating Matrix in vba

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

when i wanna get the solution of multiplying two matrix, i can use a
worksheet function.
worksheetfunction.mmult(MarixA, MatrixB)

but how can i get the solution of multiplying a number and a matrix without
using a user-defined function?
 
You can insert the following code:

newMatrix = MatrixA
For i = LBound(NewMatrix) To UBound(NewMatrix)
For j = LBound(NewMatrix, 2) To UBound(NewMatrix, 2)
newMatrix(i, j) = 3 * NewMatrix(i, j)
Next
Next

or you can put essentially identical code in a Function

Function DoNotCallMeUDF(iArray)
newMatrix = iArray
For i = LBound(newMatrix) To UBound(newMatrix)
For j = LBound(newMatrix, 2) To UBound(newMatrix, 2)
newMatrix(i, j) = 3 * newMatrix(i, j)
Next
Next
DoNotCallMeUDF = newMatrix
End Function

and code

newMatrix = DoNotCallMeUDF(MatrixA)

Why the prohibition on the latter???

Alan Beban
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top