vba 将数组值分配给excel spsh中的范围
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18471442/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
assign array values to a range in excel spsh
提问by user2200765
I have defined an array, populated it, and am attempting to set a range in an excel spsh equal to it. When I use the simple code below (I've left out the value assignments), I get the array value subscript 1 in every cell of the range. Can anyone see what's wrong? Thanks.
我已经定义了一个数组,填充了它,并试图在一个 excel spsh 中设置一个等于它的范围。当我使用下面的简单代码时(我已经省略了值分配),我在范围的每个单元格中都得到了数组值下标 1。任何人都可以看到有什么问题吗?谢谢。
Dim Loss(1 To 10000)
Range("Losses!u11:u10010") = Loss
回答by A. Webb
Excel ranges are always two dimensional
Excel 范围始终是二维的
Public Sub foo()
Dim Loss(1 To 10000, 1 To 1)
For i = 1 To 10000
Loss(i, 1) = i
Next
Range("Losses!u11:u10010") = Loss
End Sub
回答by tigeravatar
Alternately:
交替:
Range("Losses!u11:u10010").Value = Application.Transpose(Loss)