Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Copying an array to cells

Tags:

vba

I currently have an array full of data that I would like to transfer to cell G2 all the way until the entire array is exhausted. My current spreadsheet has data in G1 but no data under that.

I have the following code but it doesn't exactly work because I get the error:

Application-defined or object-defined error.

Help fixing this problem would be great. I would appreciate if you could tell me what is wrong with my code and how to fix it rather than providing me with an alternative formulation.

For i = 1 to nFlights
     With Worksheets("Q2").Range("G1")
           .End(xlDown).Offset(1, 0) = Origin(i)
    End With
Next
like image 435
user1012091 Avatar asked May 21 '26 19:05

user1012091


1 Answers

I know you didn't want to be shown code, but here's a different approach from your loop:

Dim arr
arr = Array("one","two","three","four")

ActiveSheet.Range("G2").Resize((UBound(arr) - LBound(arr)) + 1, 1).Value = _
                                  Application.Transpose(arr)
like image 81
Tim Williams Avatar answered May 24 '26 08:05

Tim Williams



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!