我有一个简短的用户定义函数,给定一个字符串和一列中的一组可能的子字符串,将返回找到的第一个子字符串的位置。
我被要求用非 VBA 公式替换 UDF。
Option Explicit
Public Function Locate(s As String, rng As Range) As Variant
Dim pos As Long, p As Long, cell As Range
Dim wf As WorksheetFunction
Set wf = Application.WorksheetFunction
Locate = CVErr(xlErrNA)
pos = 999999
For Each cell In rng
p = InStr(s, cell.Text)
If p > 0 Then
pos = wf.Min(pos, p)
End If
Next cell
If pos <> 999999 Then Locate = pos
End Function
以下是一个例子:
子字符串位于列中F. 该函数同时找到b和问并返回 5,因为问是第一位的。
我有一个适用于特定实例的公式:
=MIN(FIND({"a","b","c","d","q"},A1 & "abcdq",1))
我一直在尝试寻找一种方法来用对单元格范围的引用来替换{"a","b","c","d","q"}
和,但我不知所措。"abcdq"