PC Review


Reply
Thread Tools Rate Thread

How to assign range to Double array?

 
 
Joe User
Guest
Posts: n/a
 
      23rd Nov 2009
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.


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to assign an array to a range in Excel macro? yunlai yang Microsoft Outlook VBA Programming 6 30th Jan 2012 05:13 PM
Assign Range passed to fuction to an array Michael Microsoft Excel Programming 4 3rd Mar 2009 07:52 PM
Assign a 2D array of constant values to a range dodgo Microsoft Excel Programming 4 19th Oct 2006 04:46 AM
Assign char range/set to array? John E. Microsoft C# .NET 1 7th Jan 2005 04:35 PM
Assign Range to Array then use JOIN function Loomah Microsoft Excel Programming 5 19th Mar 2004 02:40 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:52 PM.