I am attempting to build an Excel VBA User Defined Function (UDF) that uses VLookup within the UDF to find a value from a table of dates and values. The dates are in column $A and the values in column $C
My function looks like this:
[INDENT]Function JunkTest(strA As String, strB As String, intC As Integer) As String[/INDENT]
[INDENT]
[/INDENT]
[INDENT]’ strA is a cell reference to the first column in Named Range strB, say $A$1[/INDENT]
[INDENT]’ strB is the name of a Named Range, say “JunkTable” having the range $A$1:$D$10[/INDENT]
[INDENT]’ intC is the column number of the value to be extracted by the VLookUp function with this UDF[/INDENT]
[INDENT]
[/INDENT]
[INDENT]Dim Msg, Button, Title, Response As String[/INDENT]
[INDENT]
[/INDENT]
[INDENT]JunkTest = Application.WorksheetFunction.VLookup(strA, Range(strB), intC, False)[/INDENT]
[INDENT]
[/INDENT]
[INDENT] Title = “JunkTest Function…”[/INDENT]
[INDENT] Button = vbExclamation[/INDENT]
[INDENT] Msg = “strA: ” & strA & vbCrLf & _[/INDENT]
[INDENT] “strB: ” & strB & vbCrLf & _[/INDENT]
[INDENT] “intC: ” & intC & vbCrLf & _[/INDENT]
[INDENT] “JunkTest: ” & JunkTest[/INDENT]
[INDENT] Response = MsgBox(Msg, Button, Title)[/INDENT]
[INDENT]
[/INDENT]
[INDENT]End Function
[/INDENT]
The above Function results in #VALUE!
The problem I have is how to bring the named range into the function and the expand within the VLookup function.
I also have concerns about the formation of the VLookup() statement.
Any assistance will be much appreciated.
Cheers
BygAuldByrd