求教EXCEL高手,在线等帮帮忙

A1和A2区别的字符显示在C1

你这个不同的字符应该是指不同的字符串而非单一字符吧?
如果是字符串要怎么划分哪些字符段构成一个字符呢,空格吗?
如果是以上规则,需要用代码
Sub compare()
Dim i&, j&, k%, m%, n%, p%, q%, ss$, tar$, arr, brr
j = Range("A9999").End(xlUp).Row
For i = 1 To j
ss = ""
n = Len(Cells(i, 1)) '找A列有B列无
If InStr(1, Cells(i, 1).Value, " ") > 0 Then
ReDim arr(0 To n + 1 - Len(Replace(Cells(i, 1).Value, " ", "")))
k = 0
arr(0) = 1
For m = 1 To n
If Mid(Cells(i, 1).Value, m, 1) = " " Then
k = k + 1
arr(k) = m
Else
End If
Next
arr(k + 1) = n + 1
For p = 1 To k + 1
If InStr(1, Cells(i, 2).Value, Replace(Mid(Cells(i, 1).Value, arr(p - 1), arr(p) - arr(p - 1)), " ", "")) > 0 Then
Else
ss = ss & " " & Replace(Mid(Cells(i, 1).Value, arr(p - 1), arr(p) - arr(p - 1)), " ", "")
End If
Next
Else
If InStr(1, Cells(i, 2).Value, Cells(i, 1).Value) > 0 Then
Else
ss = ss & " " & Cells(i, 1).Value
End If
End If

n = Len(Cells(i, 2)) '找B列有A列无
If InStr(1, Cells(i, 2).Value, " ") > 0 Then
ReDim arr(0 To n + 1 - Len(Replace(Cells(i, 2).Value, " ", "")))
k = 0
arr(0) = 1
For m = 1 To n
If Mid(Cells(i, 2).Value, m, 1) = " " Then
k = k + 1
arr(k) = m
Else
End If
Next
arr(k + 1) = n + 1
For p = 1 To k + 1
If InStr(1, Cells(i, 1).Value, Replace(Mid(Cells(i, 2).Value, arr(p - 1), arr(p) - arr(p - 1)), " ", "")) > 0 Then
Else
ss = ss & " " & Replace(Mid(Cells(i, 2).Value, arr(p - 1), arr(p) - arr(p - 1)), " ", "")
End If
Next
Else
If InStr(1, Cells(i, 1).Value, Cells(i, 2).Value) > 0 Then
Else
ss = ss & " " & Cells(i, 2).Value
End If
End If
Cells(i, 3) = ss
Next
End Sub
温馨提示:答案为网友推荐,仅供参考
第1个回答  2019-09-11
如果都在尾部(且多的字符都在B列)就用:
=MID(B1,LEN(A1)+1,LEN(B1)-LEN(A1))追问

谢谢,能说下公式含义吗

追答

    从B1单元格取字符串,从A1单元字符串长度加1位开始取到B1单元格字符串最后一位



解释就是len(A1)为A1单元格字符串长度

len(B1)-len(A1)为B1单元格比A1单元格字符串的长度



用下列公式可以不论A列B列单元格字符串长度

=IF(LEN(A1)<LEN(B1),SUBSTITUTE(B1,A1,,1),SUBSTITUTE(A1,B1,,1))

本回答被提问者采纳
相似回答