I want to write a User Defined Function in Excel VBA that can be used as an Excel formula, but instead of returning a value to the cell that called it, it returns a range of values to a range of other cells. This is common in many database add-ins, such as Bloomberg, CapIQ, Morningstar. I have tried different approaches but could not find out a way to accomplish it.
For example, if I put this code in cell A1, it will return 25 to cell A1.
Function AreaOfSquare(length)
AreaOfSquare = length * length
End Function
What I want, is something like this:
A B C D E
1 * Eqt1 Eqt1 Eqt2 Eqt2
2 Price vol Price vol
In cell A1, I put =DBLOOKUP(B1:F1,B2:E2, "One Year")
and it produces results like this:
A B C D E
1 * Eqt1 Eqt1 Eqt2 Eqt2
2 Price vol Price vol
3 07/14 13 100 12 200
4 06/14 14 120 13 210
5 05/14 15 140 14 220
Here are a list of approaches I have tried:
Obtain the raw data from the database Excel add-in in the form of formula. For example, I can type
=Rawdata(B1:E1, B2:E2)
and obtain the raw data. The problem is that I don't know how to call this function in VBA so that I can manipulate these data for the output, as this function is not built-in but comes with a database plugin. Alternatively, I can first obtain the raw data using the formula and then manipulate those later; the problem is that this will require two-step manipulation as I will need to type in the formula twice.Obtain the data from Java and import the data somehow. This is troublesome as I will need to configure the java application on my boss's computer environment.
Any suggestions?