实际上这个问题的答案已经在这里了。
Get the reference of a cell containing a certain text
可以在不使用宏的情况下完成,
但我遇到的问题是我想用外卡搜索某个文本。
example: DOM???text
答案 0 :(得分:1)
您可以替换InStr()
运营商的Like
功能。代码看起来像:
Public Function WhereIs(rIn As Range, sIn As String) As String
WhereIs = ""
Dim r As Range
For Each r In rIn
If r.Text Like sIn Then
WhereIs = r.Address(0, 0)
Exit Function
End If
Next r
End Function
您必须确保sIn
字符串具有正确的通配符。
答案 1 :(得分:0)
试试这个。只需运行它并在对话框中搜索单词即可。然后它会给你细胞参考。
Option Explicit
Private Sub FindText()
Dim ws As Worksheet
Dim FindString As Variant
Dim rng As Range
Set ws = ThisWorkbook.Worksheets("Sheet1")
FindString = InputBox("Search for value")
If Trim(FindString) <> "" Then
Set rng = ws.Cells.Find( _
What:=FindString, _
LookIn:=xlValues, _
LookAt:=xlPart, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False, _
SearchFormat:=False)
If Not rng Is Nothing Then
MsgBox rng.Address
Else
MsgBox "Nothing found"
End If
End If
End Sub