Friday, March 02, 2007

Transferring array to Excel range

Is there any method to transfer the contents of the array to an Excel Range.. Most often programmers used to loop thru the array and put it to the Excel (of course with another loop). Here is a simple code that will transfer the array contents to Excel. Many thanks to Sharmila Purushotaman for this thoughful article

Sub Sheet_Fill_Array()
Dim myarray As Variant
myarray = Array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
Range("A1:A10").Value = Application.WorksheetFunction.Transpose(myarray)
End Sub

' Keywords : ARRAY to Excel, Transferring array to range


  1. Hi,

    Probably not the right place to ask, but how can you convert this to Powershell ?

    $sheet = $book.Worksheets.Item(1)
    $sheet.Name = "TestInputArray"
    $msExcel.Visible = $true

    $myarray = @(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
    $sheet.Cells(2,1).resize(10,1).value = $msExcel.WorksheetFunction.Transpose($myarray)

    Any idea's are greatly appreciated.

    Kind regards,


  2. Anonymous6:26 PM

    Powershell and Excel

    Can you try the following links

  3. Anonymous10:32 AM

    REMEMBER to trim each Array value to 255 characters or less. Otherwise, the assignment fails.

  4. Hey, How to convert a 2D array to a 2D excel Range?

  5. Anonymous2:18 PM

    For an algorithm that will handle and compress data on different dimensions in multi dimensional arrays is Excel try:

  6. Hi, Thanks for this tips. Nice - it saves my time in populating each row in sheet.


Share on Facebook
Related Posts Plugin for WordPress, Blogger...
Download Windows Live Toolbar and personalize your Web experience! Add custom buttons to get the information you care about most.