Michael has attended:
Excel Advanced course
Excel VBA Intermediate course
Multi-form User-defined Functions
The built-in INDEX function contains 'two forms', an array form and a reference form. This allows users to obtain an output even if their data-set slightly differs from another data-set.
Is it possible to create a two form (or multi-form) UDF in VBA?
RE: Multi-form User-defined Functions
Hi Michael,
Thank you for the forum question.
Yes everything (almost) is possible in VBA.
What exactly do you mean by creating a two form or multi form UDF in VBA.
When you create UDFs you can work with optional arguments. The build-in index function have two options. It can find data in one array using =index(Array,Row_Num,Col_Num) or in multiple Arrays using =index(Reference,Row_Num,Col_Num,Area_Num).
What do you need with your UDF?
Kind regards
Jens Bonde
Microsoft Office Specialist Trainer
Tel: 0207 987 3777
Best STL - https://www.stl-training.co.uk
98%+ recommend us
London's leader with UK wide delivery in Microsoft Office training and management training to global brands, FTSE 100, SME's and the public sector
RE: Multi-form User-defined Functions
So I've created a function that generates an equation for a payoff diagram, or if the optional variable is provided, a profit diagram:
Function ECallG(LongPos As Boolean, Price As Integer, Strike As Integer, Underlying As Integer, Optional Quantity As Integer) As Long
'Provide an equation to graph a European Call Option's payoff, or profit if Quantity > 0
If Quantity > 0 Then
'Generate a profit graph
If LongPos = "True" Then
ECallG = Application.Max(-Price, (Underlying - Strike - Price)) * Quantity
Else: ECallG = Application.Min(Price, -(Underlying - Strike - Price)) * Quantity
End If
Else
'Generate a payoff diagram (do not consider the cost of acquiring the option)
If LongPos = "True" Then
ECallG = Application.Max(0, (Underlying - Strike))
Else: ECallG = Application.Min(0, -(Underlying - Strike))
End If
End If
End Function
I want to remove the main IF statement, and have a setup that returns a two-form function that is visual similar to the INDEX function.
RE: Multi-form User-defined Functions
Hi Michael,
As I said in my answer "Yes everything (almost) is possible in VBA."
Unfortunately I am not been able to find a solution. I have been around in cyber world but have not been able to find what you need. I have also asked the other VBA trainers for help but they couldn't help me.
Sorry I cannot help you with this one.
I had some ideas by trying calling another function from the main function but make it visible like the index function was not possible for me.
Kind regards
Jens Bonde
Microsoft Office Specialist Trainer
Tel: 0207 987 3777
Best STL - https://www.stl-training.co.uk
98%+ recommend us
London's leader with UK wide delivery in Microsoft Office training and management training to global brands, FTSE 100, SME's and the public sector