Excel VLOOKUP函数源代码

时间:2012-09-14 02:15:08

标签: excel-vba excel-formula vlookup vba excel

无论如何我可以在excel(VBA)中找到函数VLOOKUP的源代码,以便我可以修改它吗?谷歌没有给我任何帮助。谢谢!

3 个答案:

答案 0 :(得分:5)

Excel / VBA不是开源的,因此特定功能的源代码不可用。

您可以在VBA中编写自己的UDF(用户定义函数)以生成修改后的版本。

http://www.cpearson.com/Excel/FlexLookup.aspx

还有一个更灵活(非VBA)版本的VLOOKUP / HLOOKUP

答案 1 :(得分:0)

基于Vahid的回答,这对我不起作用,我做了以下代码,但是它确实有效:

Function CUSTOMVLOOKUP(lookup_value As String, table_array As Range, col_index_num As Integer)
    Dim i As Long
    For i = 1 To table_array.Rows.Count
        If lookup_value = table_array.Cells(i, 1) Then
            CUSTOMVLOOKUP = table_array.Cells(i, col_index_num)
            Exit For
        End If
    Next i
End Function

答案 2 :(得分:-1)

这是Vlookup的简单实现:

        Public Function VLOOKUP1(ByVal lookup_value As String, ByVal table_array As Range, ByVal col_index_num As Integer) As String
        Dim i As Long

        For i = 1 To table_array.Rows.Count
            If lookup_value = table_array.Cells(table_array.Row + i - 1, 1) Then
                VLOOKUP1 = table_array.Cells(table_array.Row + i - 1, col_index_num)
                Exit For
            End If
        Next i

        End Function