UDF that returns arrays from if, then, else...

wordjam

New Member
Joined
Dec 2, 2010
Messages
6
Hello,

I am new to this forum and I am new to Excel VBA. I apologize if this is redundant with another thread or post, but I have looked high and low via google and on this forum and have yet to found what I am looking for.

I started with a simple if, then, else function as follows:

Function Sample(A, B, C)

If A <= 2 And B = "down" And C = 3 Then
Sample = 0.025
ElseIf A = 3 And B = "down" And C = 3 Then
Sample = 0.1
.................
.................
ElseIf A = 5 And B = "none" And C = 5 Then
Sample = 0.6
End If
End Function

Now I would like to be able to return mutliple variables from these conditions in a 1 dimensional array that will always be bounded by say 5 or six columns. How can I get it to return multiple values such as Sample = 0.1, 0.2, 0.4, 0.2, 0.1? The sum of the array would always equal 1. I'm not sure if I should use Dim or ReDim and I don't know what the context should be.

Any help you can provided would be very much appreciated.

Thanks!

Jim
 
>100 cases. That's a lot to handle explicitly. Is there a logic between the values of A,B,C and the values returned?

Have you considered using a look up table on a worksheet to store the function data.
100 rows X 8 columns; a , b, c, sample(0), sample(1), ..., sample(4) ; might be easier to edit and maintain than 100 hard-coded VBA values.
 
Last edited:
Upvote 0

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.

Forum statistics

Threads
1,215,726
Messages
6,126,498
Members
449,316
Latest member
sravya

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