excel中的模糊查询问题

[复制链接]
查看11 | 回复2 | 2010-11-4 09:56:32 | 显示全部楼层 |阅读模式
有如下工作(例子):EXCEL中有单元格M2,可能出现a、b、c、ab、bc、ac、abc、不存在a或b或c这这八种情况,现在在M3中要显示出这八种情况的可能存在的一种,使用公式如下,为能够容易看出层次,我如下方式写:
if( iserror(search(m2,"a"))
,

if(iserror(search(m2,"b"))

,

if(iserror(search(m2,"c")),"nothing",c")

,

if(iserror(search(m2,"c")),"b","b&c")

)
,

if(iserror(search(m2,"b"))

,

if(iserror(search(m2,"c")),"a","a&c")

,

if(iserror(search(m2,"c")),"a&b","a&b&c")

)
)
答案如下
'判断是否存在单个字串
Function LikeChar(text, char)
flag = Len(text) - Len(Replace(text, char, ""))
If flag = 0 Then

LikeChar = True
Else

LikeChar = False
End If
End Function
'输出八种情况中的一种
Function LikeChar2(str, str1, str2, str3)
If LikeChar(str, str1) Then

If LikeChar(str, str2) Then

If LikeChar(str, str3) Then

LikeChar2 = "无手续"

Else

LikeChar2 = str3

End If

Else

If LikeChar(str, str3) Then

LikeChar2 = str2

Else

LikeChar2 = str2 + "&" + str3

End If

End If
Else

If LikeChar(str, str2) Then

If LikeChar(str, str3) Then

LikeChar2 = str1

Else

LikeChar2 = str1 + "&" + str3

End If

Else

If LikeChar(str, str3) Then

LikeChar2 = str1 + "&" + str2

Else

LikeChar2 = str1 + "&" + str2 + "&" + str3

End If

End If
End If
End Function

回复

使用道具 举报

千问 | 2010-11-4 09:56:32 | 显示全部楼层
=IF(AND(ISERROR(FIND("a",M2)),ISERROR(FIND("b",M2)),ISERROR(FIND("c",M2))),"nothing",MID(IF(ISERROR(FIND("a",M2)),"","&a")&IF(ISERROR(FIND("b",M2)),"","&b")&IF(ISERROR(FIND("c",M2)),"","&c"),2,10))
回复

使用道具 举报

千问 | 2010-11-4 09:56:32 | 显示全部楼层
不知道你想问什么,但我觉得=IF(M2="","nothing",IF(LEN(M2)=2,LEFT(M2)&"&"&RIGHT(M2),LEFT(M2)&"&"&MID(M2,2,1)&"&"&RIGHT(M2)))就可以
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行