Microsoft requires the parameter of the MInverse method of data type Variant (http://msdn.microsoft.com/en-us/library/bb239421.aspx). Try declaring CoArrInv as Variant (as in Dim CoArrInv(3,3) As Variant).
Hope this helped, Rolf On Oct 18, 10:36 pm, seryozha <seryozha.sundst...@gmail.com> wrote: > Hello all, > > I am attempting to write code for a Macro that will solve for > simultaneous equations. I Have 4 equations and 4 unknowns. I really > want (need) to do this using the Matrix operations (MInverse and > MMult) and therefore arrays. > > I created a user form so the user may input the coefficients and then > a button to calculate the unknowns. > The problem I am having, is i get a "Can't assign to array" and it > highlights the 'CoArrinv' Line. I have an inkling that it has to do > with Dim statements. > Thanks in advance for any help received, > Seryozha > > The code for the Sub button is below, but some notes first: > eq1x1,eq1x2.....eq2x4 relate to a textbox in the userform. eq stands > for equation, x1 stands for unkown. > Labelx1 and so forth are labels that correspond to the unkown variable > (x1,x2,x3, and x4) > > Private Sub CommandButton1_Click() > Dim CoArray(3, 3) As Integer, Zarray(3) As Integer, CoArrInv(3, 3) As > Integer, xArray(3) As Integer > Dim x1, x2, x3, lblx1, blbx2, lblx3 As Long > CoArray(0, 0) = Val(eq1x1.Value) > CoArray(0, 1) = Val(eq1x2.Value) > CoArray(0, 2) = Val(eq1x3.Value) > CoArray(0, 3) = Val(eq1x4.Value) > > CoArray(1, 0) = Val(eq1x1.Value) > CoArray(1, 1) = Val(eq1x2.Value) > CoArray(1, 2) = Val(eq1x3.Value) > CoArray(1, 3) = Val(eq1x4.Value) > CoArray(2, 0) = Val(eq2x1.Value) > > CoArray(2, 1) = Val(eq2x2.Value) > CoArray(2, 2) = Val(eq2x3.Value) > CoArray(2, 3) = Val(eq2x4.Value) > CoArray(3, 0) = Val(eq3x1.Value) > > CoArray(3, 1) = Val(eq3x2.Value) > CoArray(3, 2) = Val(eq3x3.Value) > CoArray(3, 3) = Val(eq3x4.Value) > > Zarray(0) = Val(eq1z.Value) > Zarray(1) = Val(eq2z.Value) > Zarray(2) = Val(eq3z.Value) > Zarray(3) = Val(eq4z.Value) > > CoArrInv = Application.WorksheetFunction.MInverse(CoArray) ' > Get "Can't assign to array" > > xArray = Application.WorksheetFunction.MMult(CoArray, Zarray) > > Labelx1 = xArray(0) > Labelx2 = xArray(1) > Labelx3 = xArray(2) > Labelx4 = xArray(3) > End Sub --~--~---------~--~----~------------~-------~--~----~ ---------------------------------------------------------------------------------- Some important links for excel users: 1. Excel and VBA Tutorials(Video and Text), Free add-ins downloads at http://www.excelitems.com 2. Excel tutorials at http://www.excel-macros.blogspot.com 3. Learn VBA Macros at http://www.vbamacros.blogspot.com 4. Excel Tips and Tricks at http://exceldailytip.blogspot.com To post to this group, send email to excel-macros@googlegroups.com If you find any spam message in the group, please send an email to: Ayush Jain @ jainayus...@gmail.com or Ashish Jain @ 26may.1...@gmail.com <><><><><><><><><><><><><><><><><><><><><><> HELP US GROW !! We reach over 6,500 subscribers worldwide and receive many nice notes about the learning and support from the group. Our goal is to have 10,000 subscribers by the end of 2009. Let friends and co-workers know they can subscribe to group at http://groups.google.com/group/excel-macros/subscribe -~----------~----~----~----~------~----~------~--~---