使用split() 处理excel里的文本字符串—转为array
使用splint()处理数据时,不受 option base 影响
Sub test2001()
Rem range("f1").value="1001|1,2005|1,1006|1,2009|1,2006|1,4001|60"
arr1 = Split(Range("f1"), ",")
For i = 0 To UBound(arr1)
Debug.Print arr1(i)
Next i
End Sub
转2维数组
拆解2维数组的例子—没搞定
Sub testarr1()
Rem 把一个字符串切割两次成为1个2维数组好像很难?
Rem 数据1:张三1|男,李四1|女,张三2|男,李四2|女,张三3|男,李四3|女,张三4|男,李四4|女
Rem 数据2:张三1(男),李四1(女),张三2(男),李四2(女),张三3(男),李四3(女),张三4(男),李四4(女)
Dim arr1
Dim arr2
arr1 = Split(Range("F1"), ",")
For i = 1 To UBound(arr1)
ReDim arr2(1 To i, 1 To 2)
arr2(i, 1) = Split(arr1(i), "|")
' arr2(i, 1) = Application.WorksheetFunction.Mid(arr1(i).Value, 1, 3) '用Application.Left 居然不行
' arr2(i, 2) = Application.WorksheetFunction.Mid(arr1(i).Value, 5, 1)
Next
For i = 1 To UBound(arr1)
For j = 1 To 2
Debug.Print arr2(i, j)
Next j
Next i
End Sub
第2个方法好了点?
Sub testarr1()
Rem 把一个字符串切割两次成为1个2维数组好像很难?
Rem 数据1:张三1|男,李四1|女,张三2|男,李四2|女,张三3|男,李四3|女,张三4|男,李四4|女
Rem 数据2:张三1(男),李四1(女),张三2(男),李四2(女),张三3(男),李四3(女),张三4(男),李四4(女)
Dim arr1
Dim arr2
arr1 = Split(Range("F1"), ",")
For i = 1 To UBound(arr1)
ReDim arr2(1 To i, 1 To 2)
arr2(i, 1) = Left(arr1(i), 3) '用Application.Left 居然不行
arr2(i, 2) = Right(arr1(i), 1)
Next
For i = 1 To UBound(arr1)
For j = 1 To 2
Debug.Print arr2(i, j)
Next j
Next i
End Sub