|
Sub 转换()
Dim fengefu As String, s As String
Dim n As Long, i As Long, j As Long, l As Long
Dim a As Long, b As Long, c As Long
fengefu = Application.InputBox("请输入分隔符")
Application.Range("a1", Range("a1").End(xlDown)).Select
n = Selection.Rows.Count
For i = 1 To n
l = Len(Selection.Cells(i))
a = 0
b = 1
For j = 1 To l
s = Mid(Selection.Cells(i), j, 1)
If fengefu = s Then
b = j
c = Mid(Selection.Cells(i), a + 1, b - a - 1)
Selection.Cells(1).End(xlDown).Offset(1, 0).Value = c
Selection.Cells(1).End(xlDown).Offset(0, 1).Value = Selection.Cells(i).Offset(0, 1)
Selection.Cells(1).End(xlDown).Offset(0, 2).Value = Selection.Cells(i).Offset(0, 2)
a = b
ElseIf j = l Then
b = j
c = Mid(Selection.Cells(i), a + 1, b - a)
Selection.Cells(1).End(xlDown).Offset(1, 0).Value = c
Selection.Cells(1).End(xlDown).Offset(0, 1).Value = Selection.Cells(i).Offset(0, 1)
Selection.Cells(1).End(xlDown).Offset(0, 2).Value = Selection.Cells(i).Offset(0, 2)
End If
Next
Next
End Sub
有一点条件 就是我的代码是从A1开始 如果你会修改的话 把起始单元格调整一下,另外就是数据下面不要留任何东西 |
|