如果在EXCEL的A1单元格里有数据:1,2,3,4,5,6,7,8, 在A2单元格里有数据:1,3,4,8,

2024-12-16 05:56:05
推荐回答(2个)
回答1:

代码如下:

Function SFR(S1 As Range, s2 As Range)
Dim i, j As String
Dim sa, sb As String
sa = S1 & ","
sb = s2 & ","
For i = 1 To Len(sb) - 1 Step 2
sbs = Mid(sb, i, 2)
If InStr(1, sa, sbs) Then
sa = Replace(sa, sbs, "")
End If
Next i
sa = Left(sa, Len(sa) - 1)
SFR = sa
End Function

按Alt+F11打开VBE编辑器,插入-代码,复制粘贴上面的代码后返回工作表,A3单元格中输入:
=SFR(A1,A2)
回车后即可实现。

回答2:

A3输入 =GetA3(A1)

Function GetA3(MyRng As Range)
Dim Arr2, G
G = MyRng.Text
Arr2 = Split(Cells(MyRng.Row + 1, MyRng.Column).Text, ",")
For I = LBound(Arr2) To UBound(Arr2)
If Arr2(I) <> "" Then G = Replace(G, Arr2(I) & ",", "")
Next
GetA3 = G
End Function