multplying matrix with constant doesn't work in VBA

A

a321654987

I have a matrix like this...

12 4 22
2 1 33
54 2 9


....and the following function...


Function myfunc(m)


myfunc = 2 * m


End Function


Passing on the matrix to exactly this funciton (letter by letter) in
Excel 2003 SP2 results in #VALUE!


Why? What is wrong here? My guess is that some data type definitions
are missing. Can somebody help?
 
J

Jon Peltier

You'll just have to loop through the rows and columns to multiply each
matrix element individually.

- Jon
 
A

a321654987

You'll just have to loop through the rows and columns to multiply each
matrix element individually.
I did a function which is exactly doing that.

The thing I don't understand why this is possible in a spreadsheet. For
example, naming the above mentioned matrix "aMatrix", the following
formula would product the correct result: {= 2*aMatrix}. Weird stuff,
in my opinion.
 
J

Jon Peltier

The worksheet is set up to treat worksheet ranges as a matrix in a similar
sense to our algebraic understanding of them. VBA doesn't know it's backing
up a spreadsheet program. The only difference between VBA for Excel, Word,
PowerPoint, and other applications is an object model that provides
application-specific objects and their properties and methods. VBA can
handle an array fine, although it makes you deal with the array elements
individually.

- Jon
 

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

Top