Public Function 定表查找(strFind As String) As String
Dim i As Integer
Dim LastRow As Long
Dim rg1, rg2 As Range
LastRow = Worksheets("参考模板").UsedRange.Rows.Count '获得使用的行数
' strFind = "格式上"
i = 1
Set rg1 = Worksheets("参考模板").Range("B" & i & ":" & "B" & LastRow).Find(strFind, LookIn:=xlValues)
If Trim(strFind) <> "" Then
If Not rg1 Is Nothing Then
For i = rg1.Row To LastRow
Set rg2 = Worksheets("参考模板").Range("B" & i & ":" & "B" & LastRow).Find(strFind, LookIn:=xlValues)
If Not rg2 Is Nothing Then
' Debug.Print i & "--"
fnc定表查找 = fnc定表查找 + Worksheets("参考模板").Range("B" & i).Value & Chr(10)
End If
Next
Else
Debug.Print "未找到相关记录!"
' MsgBox "未找到相关记录!", 0, "提示:"
End If
Else
MsgBox "请输入要查找的数据!", 0, "提示:"
End If
End Function
Author: LiW