scottcolbury
New Member
- Joined
- Dec 6, 2005
- Messages
- 45
Hi all,
I'm trying to use this function from VB Numerical Methods:
http://www.vbnumericalmethods.com/download.asp?codeType=m&cTitle=Cholesky Factorization
... and here is my code:
However, I keep getting a runtime '424' error for object required.
I've been told that sometimes VBA doesn't allow you to pass ranges into a function. Any help on this one?
Also, the code from VB Numerical Methods creates an array.
I can't figure out the syntax to get that data back out of the function and into my spreadsheet. I'd like to do this within the sub rather than the function itself.
Any ideas?
thanx,
s_c[/code]
I'm trying to use this function from VB Numerical Methods:
http://www.vbnumericalmethods.com/download.asp?codeType=m&cTitle=Cholesky Factorization
Code:
Function Cholesky(Mat As Range)
Dim A, L() As Double, s As Double
A = Mat
n = Mat.Rows.Count
M = Mat.Columns.Count
If n <> M Then
Cholesky = "?"
Exit Function
End If
ReDim L(1 To n, 1 To n)
For j = 1 To n
s = 0
For k = 1 To j - 1
s = s + L(j, k) ^ 2
Next k
L(j, j) = A(j, j) - s
If L(j, j) <= 0 Then Exit For
L(j, j) = Sqr(L(j, j))
For i = j + 1 To n
s = 0
For k = 1 To j - 1
s = s + L(i, k) * L(j, k)
Next k
L(i, j) = (A(i, j) - s) / L(j, j)
Next i
Next j
Cholesky = L
End Function
... and here is my code:
Code:
Sub testcholesky()
Dim x As Range
Set x = Sheet6.Range(Cells(12, 12), Cells(12 + 53 - 1, 12 + 53 - 1))
Cholesky (x)
End Sub
However, I keep getting a runtime '424' error for object required.
I've been told that sometimes VBA doesn't allow you to pass ranges into a function. Any help on this one?
Also, the code from VB Numerical Methods creates an array.
I can't figure out the syntax to get that data back out of the function and into my spreadsheet. I'd like to do this within the sub rather than the function itself.
Any ideas?
thanx,
s_c[/code]