Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VBA How to display array in message box

Tags:

arrays

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
like image 223
Aadil Avatar asked Jan 23 '15 11:01

Aadil


1 Answers

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.

like image 76
Caio César S. Leonardi Avatar answered Sep 22 '22 05:09

Caio César S. Leonardi