#名称? Excel工作表中的错误

时间:2013-06-09 19:33:51

标签: excel vba syntax-error user-defined-functions

Excel返回错误#NAME?当我尝试在工作表中引用此功能时。我在这里做错了什么?

该功能的目标是查看列表以比较输入的数字和名称,然后根据该名称返回一串附加信息。

Function Cname(Name As String, Number As Integer) As String
    x = 3
    For x = 3 To x = 6857
    If Name = Worksheets("Master List").Cells(x, 2).Value Then

        If Number = Worksheets("Master List").Cells(x, 3).Value Then
            Cname = Worksheets("Master List").Cells(x, 1).Value
            End Function
        End If

    Else
        x = x + 1

    End If
End Function

感谢。

1 个答案:

答案 0 :(得分:0)

=INDEX('Master List'!A3:A6857, MATCH(1, ('Master List'!B3:B6857="NameBeingSearched") * ('Master List'!C3:C6857=NumberBeingSearched),0))

将上述公式粘贴到单元格中(您可以使用CName功能) 而不是按输入,按 ctrl + shift + 输入

这有帮助吗?

礼貌:http://www.mrexcel.com/forum/excel-questions/306615-vlookup-multiple-criteria.html

编辑:使用VBA

Function Cname(Name As String, Number As Integer) As String
    dim x as integer
    x = 3
    For x = 3 To 6857
       If Name = Worksheets("Master List").Cells(x, 2).Value Then
          If Number = Worksheets("Master List").Cells(x, 3).Value Then
             Cname = Worksheets("Master List").Cells(x, 1).Value
              End Function
          End If
       End If
    Next
End Function