Custom function that returns value from named table

EnderSpy

New Member
Joined
Feb 23, 2021
Messages
4
Office Version
  1. 2019
Platform
  1. Windows
First of all, I'm quite of a begginer in VBA.

I'm trying to create a function that returns a cell inside a table if I specify the value of the row and column using a combination of INDEX and MATCH.

This is my code:

VBA Code:
Function ReturnValueFromTable(Table As String, LookUpValue1 As String, LookUpArray1 As String, LookUpValue2 As String, LookUpArray2 As String) As Double

ReturnValueFromTable = Application.WorksheetFunction.Index(Range(Table), Application.WorksheetFunction.Match(LookUpValue1, Range(LookUpArray1), 0), Application.WorksheetFunction.Match(LookUpValue2, Range(LookUpArray2), 0))

End Function

Then when writing the function inside a cell I place named ranges in table, LookUpArray1 and LookUpArray2 and cells in LookUpValue1 and LookUpValue2

Something like this: =ReturnValueFromTable(Table1;M2;ExampleColumn;N2;ExampleRow)

It returns #VALUE!
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
VBA Code:
Function ReturnValueFromTable(Table As Range, LookUpValue1 As String, LookUpArray1 As Range, LookUpValue2 As String, LookUpArray2 As Range) As Double
    ReturnValueFromTable = Application.WorksheetFunction.Index(Table, Application.WorksheetFunction.Match(LookUpValue1, LookUpArray1, 0), Application.WorksheetFunction.Match(LookUpValue2, LookUpArray2, 0))
End Function
 
Upvote 0
VBA Code:
Function ReturnValueFromTable(Table As Range, LookUpValue1 As String, LookUpArray1 As Range, LookUpValue2 As String, LookUpArray2 As Range) As Double
    ReturnValueFromTable = Application.WorksheetFunction.Index(Table, Application.WorksheetFunction.Match(LookUpValue1, LookUpArray1, 0), Application.WorksheetFunction.Match(LookUpValue2, LookUpArray2, 0))
End Function
I also tried that, and it still doesn't work


RimworldManager.xlsm
PQRSTUVW
1612345#VALUE!
1711112131415
18221222324241
1933132333435
20441424344452
2155152535455
RimworldManager Values
Cell Formulas
RangeFormula
W16W16=ReturnValueFromTable(table,W18,column,W20,row)
Named Ranges
NameRefers ToCells
column='RimworldManager Values'!$P$17:$P$21W16
row='RimworldManager Values'!$Q$16:$U$16W16
table='RimworldManager Values'!$Q$17:$U$21W16
 
Upvote 0
Try
VBA Code:
Function ReturnValueFromTable(Table As Range, LookUpValue1 As Variant, LookUpArray1 As Range, LookUpValue2 As Variant, LookUpArray2 As Range) As Double
    ReturnValueFromTable = Application.Index(Table, Application.Match(LookUpValue1, LookUpArray1, 0), Application.Match(LookUpValue2, LookUpArray2, 0))
End Function
 
Upvote 0
Solution
Try
VBA Code:
Function ReturnValueFromTable(Table As Range, LookUpValue1 As Variant, LookUpArray1 As Range, LookUpValue2 As Variant, LookUpArray2 As Range) As Double
    ReturnValueFromTable = Application.Index(Table, Application.Match(LookUpValue1, LookUpArray1, 0), Application.Match(LookUpValue2, LookUpArray2, 0))
End Function
It worked, thanks ?
 
Upvote 0
Glad we could help & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,801
Messages
6,121,644
Members
449,045
Latest member
Marcus05

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