Sub RemoveDuplicates() Dim lastRow As Long Dim i As Long, j As Long Dim strA As String, strB As String, strC As String

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

For i = 1 To lastRow - 1
    strA = ActiveSheet.Cells(i, "A")
    strB = ActiveSheet.Cells(i + 1, "B")
    strC = ""
    
    For j = 1 To Len(strA)
        If Mid(strA, j, 1) = Mid(strB, j, 1) Then
            strC = strC
        Else
            strC = strC & Mid(strA, j, 1)
        End If
    Next j
    
    ActiveSheet.Cells(i, "C") = strC
Next i

End Sub

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

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

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