我编写了一个函数,用于搜索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
答案 0 :(得分:0)
问题解决了...... :) 问题是,在Office excel 2011 for MAC上,find方法无法正常工作。 请参阅此链接以获取由Rick Rothstein发布的变通方法: http://www.mrexcel.com/forum/excel-questions/878953-excel-visual-basic-applications-function-works-code-but-not-udf-spreadsheet.html