A function has to have a return type (long, integer, double, string,
etc.) depending on the value of what you are returning.
Also, exactly what is Vector1? Is it a range of cells or an array of
values? What about DotProd? Is it the product of all of the values of
the cells in Vector1? Show us the math that would normally be done.
One possible interpretation (assuming Vector1 is a Range) (not tested):
Public Function DotProd(Vector1 as Range) as Double
Dim rngCell as Range
Dim dblDotProd as Double
dblDotProd = 1
For each rngCell in Vector1
dblDotProd = dblDotProd*rngCell.Value
next rngCell
Thanks everyone for your suggestions. Actually, the code I posted is a very
simple and complete version of of what I'm trying to do. You no doubt have
guessed that I am a complete new-comer to VBA programming. After a lot of
head scratching I came up with the code that Ron suggested and it works fine.
The function name is unimportant but it will eventually be a dotproduct
routine that doesn't care about the orientation of the two vectors. I'm
nearly finished with that.
My next project will be to row-reduce a matrix to canonical and echelon
form. In that case I will have to return another matrix, and I havent
figured out how to do that. Any suggestions would be welcome.
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.