vba,数组添加

vba,数组添加现在我有n个值,添加到数组a中。当有一个值b=数组中任意值时。则执行。怎么写?大哥详细点。包括数值添加。数值内值为条件添加进入的。如cells(i,1)=6 then,添加cells(i,2)

sub bijiao()
dim a()
dim i as long
dim b
'定义数组
redim a(0 to 10)
'数组赋值
for i=0 to ubound(a)
a(i)=i
next
'b赋值
b=6
'循环比较
for i=0 to ubound(a)
if b=a(i) then exit for
next
'判断是否找到
if i>ubound(a) then
msgbox "没有找到"
else
redim preserve a(0 to ubound(a)+1)
a(ubound(a))=b
end if
end sub追问

a()数组值是文本或其它类型10个,a(i)是指数组a()中第i个值吗?可以不进行循环比较直接确认b是否在a()中吗

or函数的效果

追答

数组不可以,用Dictionary或Collection对象可以。

追问

我想到了字典,用的不好,只会在固定模板上做些小修改

温馨提示:答案为网友推荐,仅供参考