Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations cowski on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Matrix Inverse in VBA Excel 1

Status
Not open for further replies.
Replies continue below

Recommended for you

Two changes will get it working:

1. Your matrix does not have an inverse (check it with MInverse on the spreadsheet). I have changed the value at (3,3) to -33 to fix that.

2. You can't assign an array to a double array. You need to declare Tstr as a variant: Public Tstr As Variant

With those two changes it will work.

A few other points:
3. It is better to declare all integers as long, because VBA converts integers to long anyway, and if you always use long you don't need to think about whether to use integer or long.

4. You can return the result array to the spreadsheet in a single operation, rather than calling the check function 9 times (which calls the inverse sub 9 times. so:

Code:
Function Check2()
Call MomD
Check2 = Tstr
End Function

will return the full array. When you enter the function you will only see (1,1) of course. To see the whole array:
Select a 3x3 range, with the function in the top left corner
Press F2
Press Ctrl-shift-enter

5. You can pass a worksheet range, do the inverse, and return the result in a single function:
Code:
Function Check3(mrange As Variant)
Check3 = WorksheetFunction.MInverse(mrange)
End Function

Doug Jenkins
Interactive Design Services
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor