如果在EXCEL的A1单元格里有数据:1,2,3,4,5,6,7,8, 在A2单元格里有数据:1,3,4,8,
现在要在A3单元格里输出的是:2,5,6,7,(即在A1中将A2中的数据删掉)求VBA(自定义函数)。(保证A2中的数据都在A1中)...
现在要在A3单元格里输出的是:2,5,6,7,(即在A1中将A2中的数据删掉)
求VBA(自定义函数)。(保证A2中的数据都在A1中) 展开
求VBA(自定义函数)。(保证A2中的数据都在A1中) 展开
2个回答
展开全部
代码如下:
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)
回车后即可实现。
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)
回车后即可实现。
展开全部
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
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
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询