1

Can anyone explain to me why this works:

Dim myArr As Variant `or, myArr()`
myArr = Array("Brian", "Steve", "Dan", "Mark", "Tom")

And this doesn't:

Dim myArr As String
myArr = Array("Brian", "Steve", "Dan", "Mark", "Tom")

I get Run-time error '13': Type mismatch

3
  • 2
    Because the Array statement returns a Variant. Even if you declared a string array (Dim myArr() as String) it wouldn't work. Commented Apr 21, 2016 at 13:13
  • Consider Dim myArr() as String and then myArr = Split("Brian,Steve,Dan,Mark,Tom", ","). Commented Apr 21, 2016 at 13:26
  • That works nicely, too! Thanks! Commented Apr 21, 2016 at 13:35

1 Answer 1

3

That's because the function Array returns a Variant:

https://msdn.microsoft.com/en-us/library/aa262675(v=vs.60).aspx

Sign up to request clarification or add additional context in comments.

Comments

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.