|
我这有一个自定义的,你参考下:- Function LOOK(查找值 As String, 区域 As Range, Optional 列 As Integer = 2, Optional 索引号 As Integer = 1) As String
- Application.Volatile '将自定义函数标记为易失性函数,无论何时在工作表的任意单元格中进行计算时,易失性函数都必须重新进行计算
- Dim i As Long, cell As Range, Str As String
- With 区域(1).Resize(区域.Rows.Count, 1)
- If .Cells(1) = 查找值 Then Set cell = .Cells(1) Else Set cell = .Find(查找值, LookIn:=xlValues)
- If Not cell Is Nothing Then
- Str = cell.Address
- Do
- i = i + 1
- If i = 索引号 Then LOOK = cell.Offset(0, 列 - 1): Exit Function
- Set cell = 区域.Find(查找值, cell)
- Loop While Not cell Is Nothing And cell.Address <> Str
- End If
- End With
- End Function
复制代码
|
|