vba 将一列数字读入数组的最快方法

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11504024/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 13:33:17  来源:igfitidea点击:

Fastest way to read a column of numbers into an array

arraysexcelvbaexcel-vba

提问by AZhu

Say if I have a column of numbers (how many of them could vary, but could be anywhere between 1000-10000) and I would like to read all of them into an array in VBA, what is the fastest way of doing so?

假设我有一列数字(其中有多少可能会有所不同,但可能介于 1000-10000 之间)并且我想将所有数字读入 VBA 中的数组,那么最快的方法是什么?

Obviously I can create an array of size 10000 and do a for/while-loop but is there any way that's faster than this?

显然我可以创建一个大小为 10000 的数组并执行 for/while 循环,但是有没有比这更快的方法?

回答by Siddharth Rout

Like this?

像这样?

Dim Ar as Variant

Ar = Sheets("Sheet").Range("A1:A10000").Value

If you do not know the last row then you can find the last row using thisand then use the above code as

如果你不知道最后一行,那么你可以使用这个找到最后一行,然后使用上面的代码作为

Ar = Sheets("Sheet").Range("A1:A" & LRow).Value