- Sub aa()
- Dim ar, i&, ar1, k&, ar2(), m&, n%
- n = Application.InputBox("请输入姓名中需要间隔的空格数量:", "输入", , , , , , 1)
- With Sheet1
- ar = .[a2:a4]
- m = 1
- For i = 1 To UBound(ar)
- ar1 = Split(Split(ar(i, 1), ":")(1), "、")
- For k = 0 To UBound(ar1)
- m = m + 1
- ReDim Preserve ar2(1 To 2, 1 To m)
- ar2(1, 1) = "姓名"
- ar2(2, 1) = "班级"
- ar2(2, m) = Split(ar(i, 1), ":")(0)
- If Len(Trim(ar1(k))) = 2 Then
- ar2(1, m) = Application.WorksheetFunction.Replace(ar1(k), 2, 0, Application.Rept(" ", n))
- Else
- ar2(1, m) = ar1(k)
- End If
- Next
- Next
- .[j1].Resize(UBound(ar2, 2), UBound(ar2, 1)) = Application.Transpose(ar2)
- End With
- End Sub
复制代码 |