你好!楼主的问题没有描述清楚,自然也就没法解决。这样吧,给楼主写一个VBA程序代码,楼主可以根据实际需要进行修改。
一、VBA程序代码如下:(写代码不易,望笑纳)
Sub Replace_N()
Dim i1, i2, i3, i4, i5, arr, str, str2
On Error Resume Next '忽略运行过程中可能出现的错误
Set mysheet1 = ThisWorkbook.Worksheets("Sheet1") '定义工作表Sheet1
arr = Array("韩", "美剧") '要查找的字符组,可自己加进来
For Each str In arr '对字符组逐一查找
i2 = 0
For i1 = 1 To 1000 '从第1行到1000行
If mysheet1.Cells(i1, 1) <> "" Then '如果单元格不是空白,则
i3 = 0
str2 = mysheet1.Cells(i1, 1).Value
For i4 = 1 To Len(mysheet1.Cells(i1, 1)) '执行的次数从1到单元格的字符串长度
i3 = InStr(i3 + 1, str2, str) '获取字符串所在的位置
If i3 > 0 Then
i2 = i2 + 1
If i2 > 1 Then
str2 = Application.WorksheetFunction.Replace(str2, i3, Len(str), "") '替换成空白
End If
End If
If i3 = 0 Then
Exit For
End If
Next
mysheet1.Cells(i1, 1) = str2
End If
Next
Next
End Sub
二、VBA程序的执行结果如下:
追问我想要的结果是 【韩剧0123456美M】顺序无所谓 主要是不能重复字 你重复了【 剧 0 M 1 2 3 4 5 6】