|
1 13901023680 800 | 2 13701029630 350 | 3 13601025698 560 | 如上,数据在A列,要分列,如下是我的代码,但是报错说:
类型不匹配:缺少数组或用户定义类型
Public Sub SplitBySpace()
Dim rng As Range, c As Range, arr
If Selection Is Nothing Then
MsgBox "请选中要分列的列"
Else
Set rng = Selection
End If
MsgBox Range("c1").Column
For Each c In rng.Cells
arr = Split(c.Value)
DeleteNullArrayElement arr
For i = 0 To UBound(arr)
Application.ActiveSheet.Cells(c.Row, c.Column + i).Value = arr(i)
Next
Next
End Sub
Public Function DeleteNullArrayElement(arr() As Variant)
Dim a, s As String, rslt(), index As Intege
ReDim rslt(0)
index = 0
For Each a In arr
If a <> "" Then
rslt(index) = a
index = index + 1
ReDim Preserve rslt(index)
End If
Next
ReDim arr(UBound(rslt) - 1)
arr = rslt
End Function
想知道这是为什么
|
|