vb,wps,excel 分裂

Sub 分列()
    '以空格为分隔符,连续空格只算1个。对所选中的单元格进行处理
    Dim m As Range, tmpStr As String, s As String
    Dim x As Integer, y As Integer, subStr As String
    If MsgBox("确定要分列处理吗?请确定分列的数据会覆盖它后面的单元格!", _
        vbYesNoCancel + vbQuestion) <> vbYes Then Exit Sub
    For Each m In Selection
        x = m.Column()
        y = m.Row()
        tmpStr = m.Value
        subStr = ""
        For i = 1 To Len(tmpStr)
            s = Mid(tmpStr, i, 1)
            If s = " " And subStr = "" Then  '连续的空格,忽略
            ElseIf s = " " And subStr <> " " Then '空格表示子串结束
                Cells(y, x).Value = subStr
                subStr = ""
                x = x + 1
            ElseIf s <> " " Then  '新子串开始或进行中
                subStr = subStr & s
            End If
        Next i
        If subStr <> "" Then Cells(y, x).Value = subStr
    Next m
End Sub
Sub 分列2()
    '以空格为分隔符,连续空格只算1个。对所选中的单元格进行处理
    Dim m As Range, tmpStr As String, s As String
    Dim x As Integer, y As Integer, subStr As String
    If MsgBox("确定要分列处理吗?请确定分列的数据会覆盖它后面的单元格!", _
        vbYesNoCancel + vbQuestion) <> vbYes Then Exit Sub
    For Each m In Selection
        x = m.Column()
        y = m.Row()
        tmpStr = m.Value
        subStr = ""
        For i = 1 To Len(tmpStr)
            s = Mid(tmpStr, i, 1)
            If s = "," And subStr = "" Then  '连续的空格,忽略
            ElseIf s = "," And subStr <> "," Then '空格表示子串结束
                Cells(y, x).Value = subStr
                subStr = ""
                x = x + 1
            ElseIf s <> "," Then  '新子串开始或进行中
                subStr = subStr & s
            End If
        Next i
        If subStr <> "" Then Cells(y, x).Value = subStr
    Next m
End Sub

 

转载于:https://www.cnblogs.com/--3q/p/9123413.html

已标记关键词 清除标记
表情包
插入表情
评论将由博主筛选后显示,对所有人可见 | 还能输入1000个字符
相关推荐
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页