答:如果编写一个自定义函数,可能速度会慢一点。如何是实现功能,可以利用字典对象来模拟实现,速度可能会快一点。以下是我写的2段代码e69da5e6ba90e79fa5e9819331333365653864,供参考。
1
2
3
4
5
6
7
8
9
10
11
12
|
Function
MyVlookup(LookValue
As
Range, ArrRng
As
Range, Ofst
As
Integer
)
Dim
RltRng
As
Range
Dim
AcLookValue
As
Range, AcArrRng
As
Range
Set
AcLookValue = LookValue.Cells(1, 1)
Set
AcArrRng = Intersect(ArrRng.Parent.UsedRange, ArrRng)
On
Error
Resume
Next
Set
RltRng = AcArrRng.Columns(1).Find(what:=AcLookValue, lookat:=xlPart)
On
Error
GoTo
0
If
Not
RltRng
Is
Nothing
Then
MyVlookup = RltRng.Offset(0, Ofst - 1)
End
If
End
Function
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
Sub
Demo()
Dim
Dic
As
Object
Dim
Cell
As
Range
Set
Dic = CreateObject(
"scripting.dictionary"
)
For
Each
Cell
In
Range(
"G2:G12"
)
Dic.Add Cell.Value, Cell.Offset(0, 1).Value
Next
For
Each
Cell
In
Range(
"D2:D12"
)
If
Dic.exists(Cell.Offset(0, -3).Value)
Then
Cell = Dic.Item(Cell.Offset(0, -3).Value)
End
If
Next
End
Sub
|