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: Levi Wilson   on Dec 10

Of course you are right, and many programmers prefer to avoid using
global/public variables. Passing the array  as an argument, the code  could be
rewritten:

Option Explicit

Sub AAAAA()
Dim n As Long, Trate() As Double
If Rng2Array(Selection, Trate()) Then
For n& = 1 To Selection.Cells.Count
MsgBox Trate(n&)
Next n&
End If
End Sub

Function Rng2Array(Rng As Range, InArray() As Double) As Boolean
Dim c As Range, x As Long
On Error GoTo R2Aerr
ReDim InArray(Rng.Cells.Count)
x& = 0
For Each c In Rng
x& = x& + 1
InArray(x&) = 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: