將一個包含有20個字數(shù)據(jù)的數(shù)組ARRAY分為兩個數(shù)組?
sub test()
dim arr,m(),n(),x&,i&,j&
arr=range("A1:A400")
for x=1 to ubound(arr)
if arr(x,1)>=0 then
i=i+1
redim preserve m(1 to i)'正數(shù)
m(i)=arr(x,1)
elxe
j=j+1
redim preserve n(1 to j)'負數(shù)
n(j)=arr(x,1)
end if
next x
range("B1").resize(ubound(m))=application.transpose(m)
range("C1").resize(ubound(n))=application.transpose(n)
end sub
此代碼把A列的數(shù)據(jù)按正負分別寫入B和C列,0算入正數(shù)