VBA 单元格内数据切分

有一个待切分值,内容为日期和金额,要切分成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
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。