软件:EXCEL
版本:2010
想设计一种可以一次进行多条件的模糊筛选功能
编了以下的码
Sub 多重模糊筛选()
MM = InputBox("条件有几个?")
ActiveCell.EntireColumn.Select
Select Case MM
Case 1
MM1 = InputBox("条件一")
Selection.AutoFilter Field:=1, Criteria1:="*" & MM1 & "*"
Case 2
MM1 = InputBox("条件一")
MM2 = InputBox("条件二")
Selection.AutoFilter Field:=1, Criteria1:="*" & MM1 & "*",
Operator:=xlOr, Criteria2:="*" & MM2 & "*"
Case 3
MM1 = InputBox("条件一")
MM2 = InputBox("条件二")
MM3 = InputBox("条件三")
Selection.AutoFilter Field:=1, Criteria1:="=*" & MM1 & "*",
Operator:=xlOr, Criteria2:="=*" & MM2 & "*", Operator:=xlOr, Criteria3:="=*"
& MM3 & "*"
Case 4
MM1 = InputBox("条件一")
MM2 = InputBox("条件二")
MM3 = InputBox("条件三")
MM4 = InputBox("条件四")
Selection.AutoFilter Field:=1, Criteria1:="*" & MM1 & "*",
Operator:=xlOr, Criteria2:="*" & MM2 & "*", Operator:=xlOr, Criteria3:="*" &
MM3 & "*", Operator:=xlOr, Criteria4:="*" & MM4 & "*"
Case 5
MM1 = InputBox("条件一")
MM2 = InputBox("条件二")
MM3 = InputBox("条件三")
MM4 = InputBox("条件四")
MM5 = InputBox("条件五")
Selection.AutoFilter Field:=1, Criteria1:="*" & MM1 & "*",
Operator:=xlOr, Criteria2:="*" & MM2 & "*", Operator:=xlOr, Criteria3:="*" &
MM3 & "*", Operator:=xlOr, Criteria4:="*" & MM4 & "*", Operator:=xlOr,
Criteria5:="*" & MM5 & "*"
Case 6
MM1 = InputBox("条件一")
MM2 = InputBox("条件二")
MM3 = InputBox("条件三")
MM4 = InputBox("条件四")
MM5 = InputBox("条件五")
MM6 = InputBox("条件六")
Selection.AutoFilter Field:=1, Criteria1:="*" & MM1 & "*",
Operator:=xlOr, Criteria2:="*" & MM2 & "*", Operator:=xlOr, Criteria3:="*" &
MM3 & "*", Operator:=xlOr, Criteria4:="*" & MM4 & "*", Operator:=xlOr,
Criteria5:="*" & MM5 & "*", Operator:=xlOr, Criteria6:="*" & MM6 & "*"
End Select
End Sub
目前暂定条件在6个以内 由使用者自己决定
但这如果条件3个以上就错误失败了
请问能做怎样的修正让他运作吗
谢谢