ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Display an array in a MsgBox (https://www.excelbanter.com/excel-programming/426087-display-array-msgbox.html)

Otto Moehrbach[_2_]

Display an array in a MsgBox
 
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



Per Jessen

Display an array in a MsgBox
 
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

"Otto Moehrbach" skrev i meddelelsen
...
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



Otto Moehrbach[_2_]

Display an array in a MsgBox
 
Thank you very much for that. Otto
"Per Jessen" wrote in message
...
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

"Otto Moehrbach" skrev i meddelelsen
...
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






All times are GMT +1. The time now is 11:29 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com