Calling a UDF with variable arguments within a produce

PVA0724

New Member
Joined
Apr 21, 2012
Messages
48
Hi,

I have the following funtion from the guru files page

Code:
Function VLOOKNEW(lookup_value, table_array As Range, _
           col_index_num As Integer, CloseMatch As Boolean)
' Allows for col_index_num to be negative
' that matches the lookup value.
Dim nRow As Long
Dim nVal As Integer
Dim bFound As Boolean
    VLOOKNEW = "Not Found"
    ' if positive, treat as a regular VLOOKUP
    If col_index_num > 0 Then
        VLOOKNEW = Application.WorksheetFunction.VLookup(lookup_value, _
            table_array, col_index_num, CloseMatch)
    Else
        ' Do a VLOOKUP Left
        nRow = Application.WorksheetFunction.Match(lookup_value, _
            table_array.Resize(, 1), CloseMatch)
        VLOOKNEW = table_array(nRow, 1).Offset(0, col_index_num)
    End If
End Function

which actually works great, now I'm trying to call that funtion into a new code like this

Code:
Sub Data()
Dim wks As Worksheet
Set wks = ActiveSheet
ult = wks.Cells(1048576, 1).End(xlUp).Row
For i = 2 To ult
        If wks.Cells(i, 1) <> "" Then
            wks.Cells(i, 11) = Application.Run(VLOOKNEW, wks.Cells(i, 8), Sheets("ICP Participants").Columns(2), -1, False)
        End If
Next i
End Sub

But I'm getting the error argument not optional, when I look the sintax it shows that the first one has to be the macro (I assumed here it was the funtion name?) or I'm using wrongly the "Application.Run" as I don't know any other, I'm needing assistance to help me with a new approach here.

Thanks in advance.
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
No need for application.run just call the UDF.

try this.....

Code:
wks.Cells(i, 11) = VLOOKNEW(wks.Cells(i, 8), Sheets("ICP Participants").Columns(2), -1, False)

Also double check your column index number. Are you sure -1 is what you want? Looks to me like it would be looking at a column less than column A, since column A's index number is 1. so you might want to double check what you need there.
 
Last edited:
Upvote 0
Hi

Thanks for the solution, it worked...about the -1 in the formula, this is driven by the funtion where it looks on the left to the range.

Regards
 
Upvote 0
Hi

Thanks for the solution, it worked...about the -1 in the formula, this is driven by the funtion where it looks on the left to the range.

Regards

Ahh, ok. I didn't look at it that closely, just enough to see the UDF call. Glad you got it working.
 
Upvote 0

Forum statistics

Threads
1,223,262
Messages
6,171,080
Members
452,377
Latest member
bradfordsam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top