Share via

checking name at a list

Ce 21 Reputation points
2022-01-09T20:28:39.857+00:00

hello all,
i try to write a function on vba. Function's input is name. it takes name and checking a list, if name exist, there is a discount. If name does not exist at list, it print zero related cell. But my function does not control the list and always return zero. How can i fix it? My function as follows:

Function NameDisc(vntName) As Double
    Dim vntMy_range As Variant
    vntMy_range = Worksheets("Special").Range("A1:B23")
    If vntName = Worksheets("Special").Range("A2:A23").Text Then
    NameDisc = Application.WorksheetFunction.VLookup(vntName, vntMy_range, 2, False)
    Else
    NameDisc = 0
    End If

End Function
Microsoft 365 and Office | Development | Other
Developer technologies | Visual Basic for Applications
0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.