Logo 
Search:

MS Office Answers

Ask Question   UnAnswered
Home » Forum » MS Office       RSS Feeds
  Question Asked By: Carolina Lopez   on Dec 10 In MS Office Category.

  
Question Answered By: Tyrell Thompson   on Dec 10

The following function  will take a range  argument and store  the values in its
cells in an array. Please note that if you declare the array  within the
function, it ceases to exist when the function ends.

Option Explicit

Dim Trate() As Double, MaxIdx As Long

Sub AAAAA()
Dim n As Long
If Rng2Array(Selection) Then
For n& = 1 To MaxIdx&
MsgBox Trate(n&)
Next n&
End If
End Sub

Function Rng2Array(Rng As Range) As Boolean
Dim c As Range
On Error GoTo R2Aerr
ReDim Trate(Rng.Cells.Count)
MaxIdx& = 0
For Each c In Rng
MaxIdx& = MaxIdx& + 1
Trate(MaxIdx&) = c.Value
Next c
Rng2Array = True
Exit Function
R2Aerr:
Rng2Array = False
End Function

Share: 

 

This Question has 2 more answer(s). View Complete Question Thread

 
Didn't find what you were looking for? Find more on How can I convert a Range to an Array? Or get search suggestion and latest updates.


Tagged: