0

I have an array dat that shows Type = Variant/Variant(0 to 500, 0 to 0, 0 to 1)

There is a "column" of dates:

dat(0, 0, 0) = #1/1/2013#
dat(1, 0, 0) = #1/2/2013#

I want to extract this set of dates. I tried:

Dim dat As Variant
Dim dt As Variant
'stuff gets dat in the format described above
dt = Application.Index(dat, 0, 1, 1)

Unfortunately this gives me an Error 13 Type Mismatch. What am I doing wrong?

Community
  • 1
  • 1
Jeffrey Kramer
  • 1,345
  • 6
  • 25
  • 43

1 Answers1

1

Use a Loop

Sub dural()
    Dim dat(0 To 500, 0 To 1, 0 To 1) As Variant

    dat(0, 0, 0) = #1/1/2013#
    dat(1, 0, 0) = #1/2/2013#

    Dim dt(0 To 500) As Variant

    For i = 0 To 500
        dt(i) = dat(i, 0, 0)
    Next i

End Sub
Gary's Student
  • 95,722
  • 10
  • 59
  • 99
  • Yeah, that's what I had decided on. I wasn't sure if there was a clever way to do it without the loop. – Jeffrey Kramer Aug 04 '14 at 23:24
  • 1
    @JeffreyKramer I could be mistaken but I *think* `Application.Index` only works on 2-d arrays and then only if they are base-1. (It's been a while since I tried to use it...). As for looping arrays, it's ugly/cumbersome to code, but generally more efficient than using `Application` level functions. [Here](http://stackoverflow.com/questions/18754096/matching-values-in-string-array) is one such example demonstrating that loop/iteration is up to 10x faster than using the `Application.Match` function on a vector array! – David Zemens Aug 05 '14 at 02:13