Results 1 to 3 of 3
  1. #1
    Silver Lounger
    Join Date
    Dec 2000
    Location
    California, USA
    Posts
    1,758
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Array Code for Range (XP 03)

    Would someone kindly take a look at the code in the sample workbook attached. I am having a challenge with the function recognizing the range.

    Thanks,
    John

  2. #2
    Silver Lounger
    Join Date
    Mar 2001
    Location
    Springfield, Ohio, USA
    Posts
    2,136
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Array Code for Range (XP 03)

    I'm a little confused as to what you wanted to do. Here's one possible scenario:
    <pre>Option Explicit
    Sub TestCode()
    Dim rng As Range, vArray As Variant, i As Long
    Set rng = Range("A2:E2")
    vArray = MyFunc(rng)
    For i = LBound(vArray) To UBound(vArray)
    Debug.Print vArray(i)
    Next i
    End Sub


    Function MyFunc(rng As Range) As Variant
    Dim i As Long, funcArray() As String
    ReDim funcArray(rng.Cells.Count)
    For i = 0 To UBound(funcArray) - 1
    funcArray(i) = rng.Cells(i + 1).Value
    Next
    MyFunc = funcArray
    End Function
    </pre>

    <font face="Comic Sans MS">Sam Barrett, CACI </font face=comic>
    <small>And the things that you have heard... commit these to faithful men who will be able to teach others also. 2 Timothy 2:2</small>

  3. #3
    Silver Lounger
    Join Date
    Dec 2000
    Location
    California, USA
    Posts
    1,758
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Array Code for Range (XP 03)

    Sam,

    Thank you for the assistance. The code worked just fine.

    Regards,
    John

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •