Sub RemoveRepeatedCharacters() Dim i As Integer, j As Integer, k As Integer Dim str As String, newStr As String Dim lastRow As Long

lastRow = ActiveSheet.Cells(Rows.Count, "A").End(xlUp).Row

For i = 1 To lastRow
    str = Cells(i, "A")
    newStr = ""
    For j = 1 To Len(str)
        If j = Len(str) Then
            newStr = newStr & Mid(str, j, 1)
        ElseIf Mid(str, j, 1) <> Mid(str, j + 1, 1) Then
            newStr = newStr & Mid(str, j, 1)
        End If
    Next j
    If newStr <> str Then
        Cells(i, "C") = newStr
    End If
Next i

End Sub

我需要一个excel的vba逻辑是当单元格A中有与单元格B有连续相同的字符则将单元格A中的连续相同字符删除后的数据放在单元格C列

原文地址: https://www.cveoy.top/t/topic/bh0F 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录