自定义函数Look()--Vlookup精确查找增强版
1.使look可以从左向右或者从右向左边进行查找;
2.可以返回超出第二参数范围的值; 3.速度更快; 4.防止返回值重复时会丢失之BUG。 代码: 'vlookup精确查找增强版 '强化处: '1.可以通过第四参数轻松获取重复对象,即有多个查找目标时一并罗列出来 '2.不仅可以从左向右查找,也可以从右向左查找。 '3.第二参数可以指定一列,也可以多列,函数可以在超出范违的区域中返回值 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 测试功能:
1.从左向右查找 2.超出第二参数也可以查找
3.从右向左查找
|
|