Showing posts with label array. Show all posts
Showing posts with label array. Show all posts

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

Saturday, October 3, 2015

How to create an array in VBA from an Excel range

If you have some data in Excel you want to retrieve in VBA under an Array, just use the "=" sign:

Sub create_array()
newarray = Sheets("Sheet1").Range("A1:B10").Value
MsgBox newarray(6, 2)
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