[英]Simple custom function in Excel, using Vlookup
I want to have a faster process looking up cross references. 我希望有一个更快的过程来查找交叉引用。
Right now I use VLOOKUP
, and it works fine - but it takes time when it needs to be done multiple times everyday. 现在,我使用
VLOOKUP
,它可以正常工作-但是每天需要多次执行它需要花费时间。
It is always the same sheet I use to lookup the cross references, so the only thing that changes is my input value in the VLOOKUP
function. 它始终是用于查找交叉引用的同一张纸,因此唯一更改的是我在
VLOOKUP
函数中的输入值。
Therefore I want a function where I only input 1 value to get the VLOOKUP
value. 因此,我需要一个仅输入1值即可获得
VLOOKUP
值的VLOOKUP
。
The idea is a function like: 这个想法是一个像这样的功能:
=CROSS(ID)
where 哪里
CROSS = vlookup(ID, table_array, col_index_num,[range_lookup])
So the vlookup_value
is replaced by ID
. 因此,
vlookup_value
替换为ID
。
I hope you can provide me with some answers - thanks in advance. 希望您能为我提供一些答案-预先感谢。
I have tried multiple different things, but with no success. 我尝试了多种不同的方法,但没有成功。 As I am new, I've googled and recorded macros to look for answers.
当我是新手时,我已经搜索并记录了宏以寻找答案。
You could write a UDF (user defined function) for that, using the WorksheetFunction.VLookup method : 您可以使用WorksheetFunction.VLookup方法为此编写一个UDF(用户定义函数):
Option Explicit
Public Function CROSS(ID As Variant) As Variant
CROSS = Application.WorksheetFunction.VLookup(ID, table_array, col_index_num, range_lookup)
End Function
I got it working as it should now! 我得到了它应有的作用!
The code ended up like this: 代码最终如下所示:
Sub crossref()
Option Explicit
Public Function CROSS(ID As Variant) As Variant
CROSS = Application.WorksheetFunction.VLookup(ID, Worksheets("Sheet1").Range("E:F"), 2, 0)
End Function
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.