将数组复制到单元格
我目前有一个充满数据的数组,我想将其一直传输到单元格 G2,直到整个数组耗尽。我当前的电子表格在 G1 中有数据,但在其下没有数据。
我有以下代码,但它并不完全有效,因为我收到错误:
应用程序定义或对象定义的错误。
帮助解决这个问题就太好了。如果您能告诉我我的代码有什么问题以及如何修复它,而不是为我提供替代方案,我将不胜感激。
For i = 1 to nFlights
With Worksheets("Q2").Range("G1")
.End(xlDown).Offset(1, 0) = Origin(i)
End With
Next
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我知道您不想显示代码,但这是与您的循环不同的方法:
I know you didn't want to be shown code, but here's a different approach from your loop:
offset 属性仅引用单元格(在您的情况下),该单元格位于作为调用基础的单元格(“G1”)下方。为了将整个数组原点复制到工作表上的 G 列中,请尝试以下操作:
The offset property just references the cell (in your case), one below the cell that is the base of the call ("G1"). In order to copy the whole array orgin into the column G on the sheet try this: