只是出于好奇心 - 有没有什么好方法可以将非连续数组作为连续的1D数组?
说Arr(9)=(2,5 ,,,, 25,14 ,,)到Arr(4)=(2,5,25,14)
请指导
由于
答案 0 :(得分:1)
这是一个基于循环的代码,用于删除空项:
Dim Arr as Variant , vArr2 as Variant
Dim d as Object
Dim i as integer, j as integer
Set d = CreateObject("Scripting.Dictionary")
'-- populate data array
vArr(1) = "10"
vArr(2) = "55"
vArr(3) = ""
vArr(4) = "27"
vArr(5) = ""
j = 1
For i = LBound(vArr) To UBound(vArr)
If vArr(i) <> "" Then
d.Add vArr(i), j
j = j + 1
End If
Next i
'-- pass into a new array
vArr2 = d.Keys
'-- output into sheet
Sheets(1).Range("B4").Resize(1, _
UBound(Application.Transpose(d.Keys))) = d.Keys