ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   How to assign range to Double array? (https://www.excelbanter.com/excel-programming/436539-how-assign-range-double-array.html)

Joe User[_2_]

How to assign range to Double array?
 
How can I assign the value of a range to a Double array?

The best I can do is a For Each loop. For example:

Function myIRR(myVal As Range, _
Optional myGuess As Double = 0.1)
Dim dVal() As Double, n as Long
ReDim dVal(1 To myVal.Rows.Count)
n = 0
For Each cell In myVal: n = n + 1: dVal(n) = cell: Next
myIRR = IRR(dVal, myGuess)
End Function

If dVal() were Variant, I could copy the range simply as follows:

Function myIRR(myVal As Range, _
Optional myGuess As Double = 0.1)
Dim dVal()
dVal = myVal
myIRR = IRR(dVal, myGuess)
End Function

But that results in a Type Mismatch error because the VB IRR function wants
a Double array.

PS: I know that I can use WorksheetFunction.IRR instead for this example.
I am using IRR just for demonstration purposes.




All times are GMT +1. The time now is 06:21 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com