StreetMike
New Member
- Joined
- Jun 10, 2009
- Messages
- 17
This is driving me bonkers. I don't think I've ever had this issue before but...
I have a function that takes several ranges from a spreadsheet and calculates a spline curve from them. The mechanics aren't important. Because this thing is having trouble in a REALLY WEIRD WAY. The function is below. The ranges "CFDts", "Prices", and "weights" are all non-calculated values entered into cells on the sheet. The range "CFs" is a range of calculated values. They all have the same number of cells.
The problem is in the for...next loop. The first three lines work fine to assign the range values into the requisite array. The fourth, identical, line does not work. Stepping through it and putting a watch on the variables, CFs(i).Value has a value for each i. However, after each and every assignment CF(i) has a value of 0 for every i. No error is thrown. It simply takes a value (say, 103.8987744) and calls it 0 for CF(i).
I've tried value, value2; I've tried wrapping it in a CDBL(), I've tried changing the type...the only thing which seems to work is that if I hard-code the numbers in that column (rather than having them calculate), then the assignment happens. But that's not useful!
There must be something odd that I'm doing. Suggestions?
Thanks!
Mike
Public Function ThisFunction(curveTag As String, evalDate, settledate, CFDts As Range, CFs As Range, Prices As Range, weights As Range, Knots As Range) As String
Dim P() As Double
Dim w() As Double
Dim k() As Double
Dim CF() As Double
Dim CFDates() As Double
Dim i As Integer
Dim Alphas As Variant
Dim e_d As Double
Dim s_d As Double
e_d = CDbl(CDate(evalDate))
s_d = CDbl(CDate(settledate))
ReDim P(1 To Prices.Count, 1 To 1)
ReDim w(1 To weights.Count, 1 To 1)
ReDim CFDates(1 To CFDts.Count, 1 To 1)
ReDim CF(1 To CFs.Count, 1 To 1)
For i = 1 To Prices.Count
P(i, 1) = Prices(i).Value
w(i, 1) = weights(i).Value
CFDates(i, 1) = CFDts(i).Value
CF(i, 1) = CFs(i).Value 'wth***********
Next i
...more code
I have a function that takes several ranges from a spreadsheet and calculates a spline curve from them. The mechanics aren't important. Because this thing is having trouble in a REALLY WEIRD WAY. The function is below. The ranges "CFDts", "Prices", and "weights" are all non-calculated values entered into cells on the sheet. The range "CFs" is a range of calculated values. They all have the same number of cells.
The problem is in the for...next loop. The first three lines work fine to assign the range values into the requisite array. The fourth, identical, line does not work. Stepping through it and putting a watch on the variables, CFs(i).Value has a value for each i. However, after each and every assignment CF(i) has a value of 0 for every i. No error is thrown. It simply takes a value (say, 103.8987744) and calls it 0 for CF(i).
I've tried value, value2; I've tried wrapping it in a CDBL(), I've tried changing the type...the only thing which seems to work is that if I hard-code the numbers in that column (rather than having them calculate), then the assignment happens. But that's not useful!
There must be something odd that I'm doing. Suggestions?
Thanks!
Mike
Public Function ThisFunction(curveTag As String, evalDate, settledate, CFDts As Range, CFs As Range, Prices As Range, weights As Range, Knots As Range) As String
Dim P() As Double
Dim w() As Double
Dim k() As Double
Dim CF() As Double
Dim CFDates() As Double
Dim i As Integer
Dim Alphas As Variant
Dim e_d As Double
Dim s_d As Double
e_d = CDbl(CDate(evalDate))
s_d = CDbl(CDate(settledate))
ReDim P(1 To Prices.Count, 1 To 1)
ReDim w(1 To weights.Count, 1 To 1)
ReDim CFDates(1 To CFDts.Count, 1 To 1)
ReDim CF(1 To CFs.Count, 1 To 1)
For i = 1 To Prices.Count
P(i, 1) = Prices(i).Value
w(i, 1) = weights(i).Value
CFDates(i, 1) = CFDts(i).Value
CF(i, 1) = CFs(i).Value 'wth***********
Next i
...more code