Display an array in a MsgBox

O

Otto Moehrbach

Excel XP & Win XP
I have a variable array that could be ShtArray(a,b,c) or
ShtArray(d,e,f,g,h), etc. The number of elements in the array is also a
variable, as you can see.
In proofing my code I want to find out what array the code selected, so I
used:
MsgBox "ShtArray is: " & ShtArray
which errored out with a "Type Mismatch".
What code would I use to see the elements of the selected array?
I just want to see them at this point. I don't want to do anything with
them.
Thanks for your time. Otto
 
P

Per Jessen

Hi Otto

You have to create a string with all elements from the array:

Dim MsgString As String
For i = LBound(ShtArray) To UBound(ShtArray)
If MsgString = "" Then
MsgString = ShtArray(i)
Else
MsgString = MsgString & ", " & ShtArray(i)
End If
Next
msg = MsgBox("ShtArray is: " & MsgString)

Regards,
Per
 
O

Otto Moehrbach

Thank you very much for that. Otto
Per Jessen said:
Hi Otto

You have to create a string with all elements from the array:

Dim MsgString As String
For i = LBound(ShtArray) To UBound(ShtArray)
If MsgString = "" Then
MsgString = ShtArray(i)
Else
MsgString = MsgString & ", " & ShtArray(i)
End If
Next
msg = MsgBox("ShtArray is: " & MsgString)

Regards,
Per
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top