|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
VB编的 筛选 问题
在此网址有附件 http://club.excelhome.net/thread-463702-1-1.html
VB编的 筛选 问题
想要的是,当E列有要筛选的数据时,把E列找出来,E列没有,而F列有时找出F列的数据,E和F列都有时,把这两列的数据都找出来。
E列带字母的,输入F列的数值能正确找出来。
E列不带字母的,输入F列的数值就找不出来。如:E列 6100 在对应的F列 里有3108 6131等,输入3108就找不出来
请高手给看看,很不解???
宏的密码是:1666
Const 密码 = 1666 '保护密码
Private Function FFind(x As String, y As String) As Integer
n = Len(y)
FFind = n + 1
For i = 1 To n
If Mid(y, i, 1) = x Then
FFind = i
Exit For
End If
Next
End Function
Private Sub CommandButton1_Click()
If Trim(Me.TextBox1.Text) <> "" Then
n = FFind(",", TextBox1.Text)
tj1 = Mid(Me.TextBox1.Text, 1, n - 1)
tj2 = Mid(Me.TextBox1.Text, n + 1)
Else
tj1 = ""
tj2 = ""
End If
If tj1 = "" Then
tj1 = " "
End If
If tj2 = "" Then
tj2 = tj1
End If
ActiveSheet.Unprotect Password:=密码
'下面这行中Field:=1中的1就是要筛选数据的列,
'Range("$A$1:$B$10")是数据范围
ActiveSheet.Range("$F$5:$F$6000").AutoFilter Field:=6, Criteria1:="=*" + tj2 + "*"
ActiveSheet.Range("$E$5:$E$6000").AutoFilter Field:=5, Criteria1:="=*" + "*" + "*", _
Operator:=xlOr, Criteria2:="=" + tj1
ActiveSheet.Protect Password:=密码, DrawingObjects:=True, Contents:=True, Scenarios:=True, AllowFormattingCells:=True, AllowFormattingColumns:=True, AllowFiltering _
:=True
End Sub
Private Sub CommandButton2_Click()
ActiveSheet.Unprotect Password:=密码
ActiveSheet.Range("$A$5:$L$6000").AutoFilter Field:=5
ActiveSheet.Range("$A$5:$L$6000").AutoFilter Field:=6
ActiveSheet.Protect Password:=密码, DrawingObjects:=True, Contents:=True, Scenarios:=True, AllowFormattingCells:=True, AllowFormattingColumns:=True, AllowFiltering _
:=True
End Sub
Private Sub UserForm_Activate()
Me.TextBox1.SetFocus
End Sub |
|