vba如何把while loop得到的结果放入一个array里?

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了vba如何把while loop得到的结果放入一个array里?相关的知识,希望对你有一定的参考价值。

我用while loop得到一些符合条件的结果怎么把它们放入一个array里?
如图,我想建立一个array用来存储while loop得到的结果。求大神帮忙

参考技术A '用字典吧
sub t()
    dim dic as object,i as integer
    set dic=createobject("scripting.dictionary")
    i=1
    with worksheets("Sheet1")
        do while .cells(i,4).value<>""
            if .cells(i,4).value=45 then
                dic(i)=""
            end if
            i=i+1
        loop
    end with
    rownumber=dic.keys
end sub

'数组
sub t2()
    dim i as integer,j as integer,rownumber()
    j=1
    with worksheets("Sheet1")
        i=.cells(1,4).end(xldown).row
        redim rownumber( 1 to i)
        for i=1 to ubound(rownumber)
            if .cells(i,4).value=45 then
                rownumber(j)=.cells(i,4)
                j=j+1
            end if
        loop
    end with
end sub

本回答被提问者采纳
参考技术B 使用动态数组:例如:
定义: public arrTemp() as string
初始化: redim arrTemp(0) as string

存数据时: arrTemp(ubound(arrTemp))="AAA"
redim preserve arrtemp(ubound(arrtemp)+1)
使用时: for i =0 to ubound(arrtemp)-1 step 1
msgbox arrtemp(k)
next i
详细不?可以给分了吧?谢谢!
参考技术C jiecaishidai@163.com

以上是关于vba如何把while loop得到的结果放入一个array里?的主要内容,如果未能解决你的问题,请参考以下文章