UDF Returns #Value with Table Reference

adj87

New Member
Joined
Jan 24, 2018
Messages
4
I have been trying to make a UDF to return salary based on various factors (COLA/Location, Job Title, Performance, etc). I have been running into issues incorporating ListObjects and assigning them to Ranges. I have looked at other forums and I don't know if this is possible, but I have tried passing the Table name in as a variable of the UDF and I get the same error. I would like to just assign the table within the UDF since the name will not change, just the range.

I had also hoped to add a match function to this so if the column being pointed to changed, I wouldn't have to change the UDF. Also, it adds additional readability to the code.

Code:
Function Test_Fnct(JobTitle As Variant, Branch As Variant, Salary As Variant, PQ As Variant) As Variant


Dim Result As Integer
Dim COLATable As Range
Dim PerfQtr As Range


COLATable = Sheets("COLA").ListObjects("COLA_Entry").Range.Select
COLATable_Head = Worksheets("COLA").ListObjects("COLA_Entry").HeaderRowRange.Select


Select Case JobTitle
    Case "JobA"
        If PQ = 1 Then
                Result = Application.WorksheetFunction.VLookup(Branch, COLATable, 6, False)
 
'In place of 6, I wanted to add a Match function:
'Application.WorksheetFunction.Match("JobA", COLATable_Head, 0)
'or at least 


            If Result <= Salary Then
                Test_Fnct = 0
            Else
                Test_Fnct = Result
            End If
            
        ElseIf PQ = 2 Then
                Result = Application.WorksheetFunction.VLookup(Branch, COLATable, 7, False)


            If Result <= Salary Then
                Test_Fnct = 0
            Else
                Test_Fnct = Result
            End If


        Else
            Test_Fnct = 0
        
        End If


    Case "JobB"
            Test_Fnct = 0
    
End Select


End Function

Any help would be greatly appreciated.
Thanks!
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
Hi,
maybe this would help?
Dim COLATABLE as range

Set COLATable=Sheet("COLA")....

range Varibles need to be set
 
Upvote 0
Thanks for the suggestion, that didn't solve the issue though. Simple debug of the UDF:

Code:
Sub test()
MsgBox Test_Fnct(Range("A1").Value, Range("B1").Value, Range("C1").Value, Range("D1").Value)
End Sub

and regardless, the code stops at setting COLATable = Sheets("COLA")...
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,176
Members
453,021
Latest member
Justyna P

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