[英]how to use autofilter in vba
I can't find the answer even if I search.即使我搜索也找不到答案。 I want all search results including keyword.我想要包括关键字在内的所有搜索结果。 However, the results show only part of it.然而,结果只显示了一部分。 The code below is the result of the 3 hour.. .下面的代码是 3 小时的结果......
Private Sub Worksheet_Change(ByVal Target As Range)
Dim T As String
Dim rngArea As Range
With Target
If .Address = "$CH$3" Then
If .Count > 1 Then Exit Sub
Set rngArea = Me.Range("A5").CurrentRegion
T = .Value
If IsEmpty(Target) Then
If Me.FilterMode = True Then
Me.ShowAllData: rngArea.AutoFilter
End If
Else
rngArea.Columns(66).AutoFilter 1, "=*" & T & "*", , , 0
End If
.Select
End If
End With
End Sub
I tried this too, and even when setting the field type to Text, it doesn't work.我也试过这个,即使将字段类型设置为文本,它也不起作用。 After that, I tried adding a letter in front of the data (to force it to be a string) and this worked.之后,我尝试在数据前面添加一个字母(以强制它成为一个字符串)并且这有效。 Somehow Excel still treats the data as numbers if you don't add at least one letter in the data.如果您没有在数据中添加至少一个字母,Excel 仍然以某种方式将数据视为数字。
If you're able to add a column that contains ="a" & A5, then you can perform the Autofilter on that and it should work (make sure that that column and the input field are set to Type Text).如果您能够添加包含 ="a" 和 A5 的列,那么您可以对其执行自动筛选,它应该可以工作(确保该列和输入字段设置为文本类型)。 Hacky solution though哈克解决方案虽然
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.