I am writing a UDF for Excel 2007 which I want to pass a table to, and then reference parts of that table in the UDF. So, for instance my table called "Stock" may look something like this:
Name Cost Items in Stock
Teddy Bear £10 10
Lollipops 20p 1000
I have a UDF which I want to calculate the total cost of all the items left in stock (the actual example is much more complex which can't really be done without very complex formula)
Ideally the syntax of for the UDF would look something like
TOTALPRICE(Stock)
Which from what I can work out would mean the UDF would have the signature
Function TOTALPRICE(table As Range) As Variant
What I am having trouble with is how to reference the columns of the table and iterate through them. Ideally I'd like to be able to do it referencing the column headers (so something like table[Cost]).