+ Reply to Thread
Results 1 to 2 of 2

problems with arrays

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    03-30-2010
    Location
    Manchester England
    MS-Off Ver
    Excel 2010
    Posts
    992

    problems with arrays

    Why is it that when I write the following code I get Subscript out of range on the penultimate line
    Dim OldAr()
    With Sheets("Sheet1")
    x=.range("A1").CurrentRegion.rows.Count
    reDim OldAr(x)
    OldAr = .Range(.Cells(1,1), .Cells(x,1)).value
    .Range("C2").Value = OldAr(3)
    End With
    But when I write the code
    Dim OldAr()
    With Sheets("Sheet1")
    x = .range("A1").currentRegion.Rows.count
    Redim OldAr(x)
    For a = 0 to x-1
    OldAr(a) = .Ranhe("A1").Offset(a,0).Value
    Next a
    .Range("C2").Value = OldAr(3)
    End with
    All works well
    I have used the first formulation many times without problem before. I must be doing something different but I cannot see what
    John

  2. #2
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: problems with arrays

    assigning a range to an array like that creates a 2d array so
    .Range("C2").Value = OldAr(3, 1)
    Josie

    if at first you don't succeed try doing it the way your wife told you to

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1