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?

1 Answer 1

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
Sign up to request clarification or add additional context in comments.

2 Comments

Yeah, that's what I had decided on. I wasn't sure if there was a clever way to do it without the loop.
@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 is one such example demonstrating that loop/iteration is up to 10x faster than using the Application.Match function on a vector array!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.