VBA 单元格内数据切分
2019-03-04 本文已影响0人
三载一生
有一个待切分值,内容为日期和金额,要切分成2列。

Sub SplitData()
Dim i As Integer
'待切分值
Dim Vsplit As String
'切分后的左侧值
Dim Svleft As String
'待切分的数据长度
Dim Slength As Integer
For i = 1 To UsedRange.Rows.Count
Vsplit = Cells(i, 1)
If (Vsplit <> "" And LenB(Vsplit) > 4) Then
Svleft = Left(Vsplit, 4)
Slength = LenB(Vsplit)
If (Svleft > 10) Then
Svleft = Left(Vsplit, 5)
Cells(i, 3) = Mid(Vsplit, 6, Slength - 5)
Else
Cells(i, 3) = Mid(Vsplit, 5, Slength - 4)
End If
Cells(i, 2) = Svleft
End If
Next i
End Sub