Excel范围内的一维数组 [英] One-dimensional array from Excel Range

查看:126
本文介绍了Excel范围内的一维数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在正在使用以下代码填充我的阵列证券:

I'm presently populating my array Securities with the following code:

Option Base 1
Securities = Array(Worksheets(3).Range("A8:A" & SymbolCount).Value)

产生一个二维数组,每个地址都是(1 ... 1,1 ... N)。我想要一维数组(1 ... N)。

This produces a 2-dimensional array where every address is (1...1,1...N). I want a 1-dimensional array (1...N).

我如何(a)将证券作为一维数组填充,或(b )有效地将证券剥离成一维数组(我被困在每个循环中)。

How can I either (a) populate Securities as a 1-dimensional array, or, (b) efficiently strip Securities to a 1-dimensional array (I'm stuck at a with each loop).

推荐答案

Sub test2()
    Dim arTmp
    Dim securities()
    Dim counter As Long, i As Long
    arTmp = Range("a1").CurrentRegion
    counter = UBound(arTmp, 1)
    ReDim securities(1 To counter)
    For i = 1 To counter
        securities(i) = arTmp(i, 1)
    Next i
    MsgBox "done"
End Sub

这篇关于Excel范围内的一维数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆