|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
这样?
Sub aa()
Dim ar, i&, ar1, k&, ar2(), m&, n%
n = Application.InputBox("请输入姓名中需要间隔的空格数量:", "输入", , , , , , 1)
With Sheet1
lr = .Range("a65535").End(xlUp).Row
ar = .Range("a2:a" & lr)
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 |
|