我编写了一个函数,该函数在 A:A 列中搜索字符串(作为输入传递)并返回 A:A 范围内第一个单元格的完整内容,其中包含该字符串...
当我Sub test()
从=Find_First("lala")
. 它只是返回“未找到”,尽管该段文本确实在 A:A
这是我的代码..感谢您的帮助!
Public Function Find_First(FindString As String) As String
Dim Rng As Range
Dim TrimString As String
Application.Volatile True
TrimString = Trim(FindString)
If TrimString <> "" Then
With Sheets("Sheet1").Range("A:A")
Set Rng = .Find(What:=TrimString, _
After:=.Cells(.Cells.Count), _
LookIn:=xlValues, _
LookAt:=xlPart, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)
If Not Rng Is Nothing Then
Find_First = Rng.Value
MsgBox ("Found at: " & Rng.Address)
Else
Find_First = "not found"
MsgBox ("Not found ")
End If
End With
End If
End Function
Sub test()
MsgBox Find_First(" lala ")
End Sub