EXCEL_VBA 如何添加数组元素

EXCEL_VBA 如何添加数组元素,第1张

Dim

a

......

ReDim

Preserve

a(i)

......

定义一个数组,如果比较后发现这个数为数组内没有,就让i=i+1后,重新定义一下数组,使其元素自动+1,再把值添加进去。

不明白的地方可以Q我,40194204

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


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/bake/11989556.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-20
下一篇 2023-05-20

发表评论

登录后才能评论

评论列表(0条)

保存