Sunday, March 6, 2016

How to display all the elements of an array in a message box VBA

If you want to know what is contained in your VBA array simply use the Join method:

Join(my_array,vbCr)

Example: if you want to add the following data into an array and then display the array


Sub print_array_example()

Dim arr() As Variant

ReDim arr(1 To 5) As Variant

For i = 1 To 5
    arr(i) = Cells(i, 1)
Next
  
MsgBox Join(arr, vbCr)

End Sub


 



Created by DoMyExcel.com © | Excel & VBA Consulting | Customized Excel Solutions starting at 29 USD
Services provided to Individuals and Businesses | Free Quote: DoMyExcel@gmail.com

No comments:

Post a Comment