Consulting

Results 1 to 4 of 4

Thread: Solved: Macro showing subscript out of range

  1. #1
    VBAX Tutor
    Joined
    Jan 2006
    Posts
    248
    Location

    Solved: Macro showing subscript out of range

    I am trying to get this macro to copy over column 3 to 2, but it shows subscript out of range, am I missing somthing simple?
    [VBA]Sub test()
    Dim r As Range, e
    For Each e In Array(Array("SPOT", "SPOT"), Array("TICK", "TICK"), Array("LEAVE", "LEAVE"))
    Set r = Columns(3).Find(e(0), , , xlPart, , , False)
    If Not r Is Nothing Then
    r(3, 2).Value = e(3)
    End If
    Next
    End Sub[/VBA]

    Thanks

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    There is no e(3), it is a 2-element array, so there is only e(0) and e(1).
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    VBAX Master Aflatoon's Avatar
    Joined
    Sep 2009
    Location
    UK
    Posts
    1,720
    Location
    None of your sub-arrays have four elements, so e(3) will never work.
    Be as you wish to seem

  4. #4
    VBAX Tutor
    Joined
    Jan 2006
    Posts
    248
    Location
    Ok, thanks for putting me on the right track have got it working with the following changes.
    [VBA]Sub test()
    Dim r As Range, e
    For Each e In Array(Array("SPOT", "SPOT"), Array("TICK", "TICK"), Array("LEAVE", "LEAVE"))
    Set r = Columns(3).Find(e(0), , , xlPart, , , False)
    If Not r Is Nothing Then
    r(1, 0).Value = e(1)
    End If
    Next
    End Sub
    [/VBA]

    Thank you for your assistance.

Posting Permissions

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