I have to use VBA to find the determinant ( =MDETERM ) of any size matrix/array.
This is my code for a simple 2x2 matrix but don't know how to make it dynamic (for a 3x3 or 4x4 matrix). Any ideas? I tried using something like "Dim A(1 to n, 1 to n) as Integer" but keep getting an error: "constant expression required"
This is my code for a simple 2x2 matrix but don't know how to make it dynamic (for a 3x3 or 4x4 matrix). Any ideas? I tried using something like "Dim A(1 to n, 1 to n) as Integer" but keep getting an error: "constant expression required"
Code:
Sub FindDeterminant()Dim A(1 To 2, 1 To 2) As Integer
Dim Result As Double
A(1, 1) = ActiveSheet.Cells(1, 1)
A(2, 1) = ActiveSheet.Cells(2, 1)
A(1, 2) = ActiveSheet.Cells(1, 2)
A(2, 2) = ActiveSheet.Cells(2, 2)
Result = WorksheetFunction.MDeterm(A)
ActiveSheet.Cells(14, 8) = Result
End Sub