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

A1和A2区别的字符显示在C1
2024年11月17日 00:05
有2个网友回答
网友(1):

你这个不同的字符应该是指不同的字符串而非单一字符吧?
如果是字符串要怎么划分哪些字符段构成一个字符呢,空格吗?
如果是以上规则,需要用代码
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

网友(2):

如果都在尾部(且多的字符都在B列)就用:
=MID(B1,LEN(A1)+1,LEN(B1)-LEN(A1))