+ Reply to Thread
Results 1 to 5 of 5

Using MMult output in equation

  1. #1
    Registered User
    Join Date
    12-20-2006
    Posts
    11

    Using MMult output in equation

    Hi

    I have a user function which defines two vectors (as arrays) and multiplies them together to get a single value.
    This works fine and if I stop there the function will display this value in the cell, no problem.

    However, if I want to do anything else with the value within the function e.g. add or subtract another number, then I get a #VALUE! error in the cell

    I assume this is because of some incompatibility with variable types, but can't seem to find a way to make it work.

    Any help would be much appreciated

    Please Login or Register  to view this content.

  2. #2
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,819

    Re: Using MMult output in equation

    I set up a quick spreadsheet and added a stop statement to the top of your procedure. Then, stepping through the procedure, I see that z is a variant containing a one element array after being assigned the result of the matrix multiplication (MMULT() returns an array even when it is a single element). The abc= assignment statement is treating z as a scalar variable, and you get an error. By modifying the assignment statement to treat z as an array (abc=z(1)+1), the procedure ran without error.
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

  3. #3
    Registered User
    Join Date
    12-20-2006
    Posts
    11

    Re: Using MMult output in equation

    Thanks MrShorty, that works great.

    One quick follow up if I may - I'd tried this already using Z(0) on the basis that Arrays in VBA start at zero (I thought Z(0) would give the first element in an array). Obviously this didn't work, but I don't understand why

  4. #4
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,819

    Re: Using MMult output in equation

    VBA arrays default to 0, but Excel arrays default to 1. I believe this behavior is because the MMULT() function is an Excel function, so it sends a base-1 array back to VBA.

  5. #5
    Registered User
    Join Date
    12-20-2006
    Posts
    11
    Quote Originally Posted by MrShorty View Post
    VBA arrays default to 0, but Excel arrays default to 1. I believe this behavior is because the MMULT() function is an Excel function, so it sends a base-1 array back to VBA.
    Ha, nice one Microsoft. Thanks for your help, much appreciated

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Making a macro to add a day to the output of an equation
    By tjeffords in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-07-2016, 01:11 PM
  2. MMULT and minverse
    By Granrey in forum Excel General
    Replies: 10
    Last Post: 12-02-2014, 11:24 AM
  3. mmult
    By rwgrietveld in forum Excel General
    Replies: 2
    Last Post: 10-24-2009, 04:29 PM
  4. Mmult
    By michel777 in forum Excel - New Users/Basics
    Replies: 6
    Last Post: 03-15-2007, 10:59 AM
  5. [SOLVED] MMULT
    By Dave F in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 08-10-2006, 09:37 AM
  6. [SOLVED] MMULT in VBA
    By Jim Jackson in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-31-2006, 04:08 PM
  7. [SOLVED] MMULT( )
    By Bill Martin in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-12-2006, 03:35 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1