Excel VBA: 删除单元格中重复字符并保留至C列
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
原文地址: https://www.cveoy.top/t/topic/mJSd 著作权归作者所有。请勿转载和采集!