G'Day,
I have a question more towards helping myself understand how Excel's array-formulas (Control+Shift+Enter) can read each cell dynamically into the formula.
I made an simplified example to show you what I mean.
I created a small fictional farm that has some animals, listed by names and will provide the sound of what the animal makes. In the next column I made a User Defined Function called MakesSound which takes an input of what animal it is and respond the sound that animal it makes. As shown in the snapshot picture below.
Unfortunately, I thought an arrayformula could pick up that I have different cells listing the animals and it ends like this snapshot instead.
so how can I ask the arrayformula to recognise I have different cells in Column B as I know Quacks isn't the answer for other animals. :-)
Here is another snapshot showing the formulas next to arrayformulas for comparsion and code I used as well.
Public Function MakesSound(AnimalName As String) As Variant
Select Case AnimalName
Case Is = "Duck"
MakesSound = "Quack!"
Case Is = "Cow"
MakesSound = "Moo!"
Case Is = "Bird"
MakesSound = "Tweet!"
Case Is = "Sheep"
MakesSound = "Ba-Ba-Ba!"
Case Is = "Dog"
MakesSound = "Woof!"
Case Else
MakesSound = "Eh?"
End Select
End Function
I'm open to suggestions.
Thanks, Peter.
you need to make you array function read the data into an array, process it and create an output array.
Then the array function nneeds to be entered in a multi-cell array formula (D3:D7) using ctrl-shift-enter.
The purpose of using Array formulas for the given sample is really obscure for me, but anyway, if you insist - try the following:
C3:C7
(as on your topmost screen).=MakesSound(B2:B7)
{}
brackets around it (but do NOT type them manually!).I'm not sure whether your UDF may handle array notation properly, but for usual Excel formulas this works as expected, e.g. try
=LEFT(B2:B7,2)
as an array one for step 2 - and this will return 2 starting letters from each animal name.Hope that was somehow helpful. Good luck!