我正在使用 VLookup 函数来查找列中存在的多个值。这工作得很好,但只需要很多时间,因为我在 Excel 表中有 100,000 行。
有什么办法可以加快这段代码的速度吗?
该代码基本上在列中查找特定值并获取偏移量。简单 VLookup 和 this 之间的区别在于,如果有多行具有相同的查找值,那么它会获取所有元素。
Function VLookupAll(ByVal lookup_value As String, _
ByVal lookup_column As Range, _
ByVal return_value_column As Long, _
Optional seperator As String = ", ") As String
Dim i As Long
Dim result As String
For i = 1 To lookup_column.Rows.Count
If Len(lookup_column(i, 1).Text) <> 0 Then
If lookup_column(i, 1).Text = lookup_value Then
result = result & (lookup_column(i).Offset(0, return_value_column).Text & seperator)
End If
End If
Next
If Len(result) <> 0 Then
result = Left(result, Len(result) - Len(seperator))
End If
VLookupAll = result
End Function