【问题标题】:Wrote a Macro Search that needs approximate match instead of exact编写了一个需要近似匹配而不是精确匹配的宏搜索
【发布时间】:2017-06-28 14:01:59
【问题描述】:

我编写了一个宏来通过过滤器搜索 A 列中的完全匹配,它需要近似匹配才能在 B 列中进行搜索。现在我只将它作为完全匹配,我需要帮助使其成为近似匹配码。以下是我的代码:

Sub SearchBox1()

Dim myButton As OptionButton
Dim MyVal As Long
Dim sht As Worksheet
Dim myField As Long
Dim DataRange As Range
Dim mySearch As Variant

'Load Sheet into A Variable
 Set sht = ActiveSheet

'Unfilter Data (if necessary)
 On Error Resume Next
    sht.ShowAllData
 On Error GoTo 0

 'Filtered Data Range (include column heading cells)
  ActiveSheet.Range("$A50:$L$130").AutoFilter Field:=2, Criteria1:=sht.Shapes("CountrySearch").TextFrame.Characters.Text
  Exit Sub

End Sub

感谢您的帮助!

【问题讨论】:

  • 在这种情况下,您可能需要 Criteria1:="" & sht.Shapes("CountrySearch").TextFrame.Characters.Text & ""
  • 近似匹配到底是什么意思?
  • 这取决于你想要的匹配类型:stackoverflow.com/questions/491148/…

标签: vba excel search


【解决方案1】:

尝试将 Criteria1 更改为此

如果它正在搜索字符串:

Criteria1:= "*" & sht.Shapes("CountrySearch").TextFrame.Characters.Text & "*"

或者,如果你有数字

Criteria1:= ">=" & sht.Shapes("CountrySearch").TextFrame.Characters.Text

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-10-27
    • 1970-01-01
    • 2013-09-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-19
    • 1970-01-01
    相关资源
    最近更新 更多