而论如何,二楼的回答是很有新意的,赞一个!
为你写个函数,使用起来会比较简洁,而且可以处理非数字字符。
Function Intersect(text1 As String, text2 As String) As String
Dim result As String, shorter As String, longer As String
result = ""
If Len(text1) <= Len(text2) Then
shorter = text1
longer = text2
Else
shorter = text2
longer = text1
End If
Dim i As Integer
For i = 1 To Len(shorter)
Dim searchChar As String
searchChar = Mid(shorter, i, 1)
If InStr(1, longer, searchChar) > 0 Then
If InStr(1, result, searchChar) = 0 Then '重复的字符只输出一次。
result = result & searchChar
End If
End If
Next
Intersect = result
End Function
使用方法:
在T2单元格中输入 = Intersect(M2, S2)
比如数据在A1、B1,
用数组公式:=IF(OR(ISERR(FIND(0,A1:B1))),"",0)&SUBSTITUTE(SUM(IF(MMULT(--ISNUMBER(FIND(ROW($1:$9),A1:B1)),{1;1})=2,ROW($1:$9))*10^(9-ROW($1:$9))),0,)
复制或输入完后,按CTRL+SHIFT+回车结束。
太复杂!可以使用嵌套if语句!
二楼高手
不要老想着用EXCEL自带的函数解决问题,我们可以根据自己的需要创建函数。
单击“工具”——“宏”——“VB编辑器”,在VB编辑器中插入模块,将以下代码复制进去,这样我们就创建了一个 jj(x,y) 函数。(交集的拼音首字母)
Function jj(x, y)
Dim a(10), b(10), c(10)
For i = 1 To 10
a(i) = Mid(x, i, 1)
b(i) = Mid(y, i, 1)
c(i) = ""
Next i
For i = 1 To 10
For j = 1 To 10
If a(i) = b(j) Then c(i) = a(i)
Next j
Next i
For i = 1 To 9
For j = i + 1 To 10
If c(i) = c(j) Then c(j) = ""
Next j
tt: Next i
For i = 2 To 10
c(1) = c(1) & c(i)
Next i
jj = c(1)
End Function
关闭VB编辑器,在T2单元格输入: =jj(m2,s2) 将此公式复制下去即可。
希望我的回答对你有所帮助。
在结果单元格输入公式:
=IF(COUNT(FIND(0,M2)*FIND(0,S2)),0,)&SUBSTITUTE(SUMPRODUCT(ISNUMBER(FIND(ROW($1:$9),M2)*FIND(ROW($1:$9),S2))*ROW($1:$9)*10^(9-ROW($1:$9))),0,)
向下填充即可。