8

VBA

Hi I have been trying create an array then display in a msgbox but keep getting this error:

'Invalid procedure call or argument'

I have used the Join function on another array and it works

Sub rangearray()

Dim array1 As Variant

array1 = Range("a1:z1")

MsgBox Join(array1, vbCrLf)

End Sub
2
  • 1
    You need to provide more information. Also, please tag the question so we can understand which language you're talking about. Commented Jan 23, 2015 at 11:23
  • I wrote VBA in the title, don't where its gone Commented Jan 23, 2015 at 11:38

1 Answer 1

15

I've just tested it on a simple way on VB6 and it worked with this:

Dim arr(3) As String

arr(1) = "Test"
arr(2) = "Test 2"
arr(3) = "Test 3"

MsgBox Join(arr, vbCrLf)

are you certain that your function 'Range("a1:z1")' it's actually returning an array object to the variant 'array1'?

EDIT: you can't pass a multi-dimensional array on Join function, it has to be an One-dimensional to work properly. So, if the expression array1(1,1) returns an value, that's your problem.

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

3 Comments

I tried your script and it worked, I don't what the issue is with using range?
i don't know either what that function is returning, but the point is, put a break point on the MsgBox line. Then, check the value of 'array1', it should be an array, because the "Join" function is expecting an array.
you can't pass a multi-dimensional array on Join function, it has to be an One-dimensional to work properly. So, if the expression array1(1,1) returns an value, that's your problem.

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.