Hi everyone,
Thanks for your replies.
Tushar - I assure you I'm not heading down the efficiency road with this!
Nate - Fully recoverd from your birthday hangover, at last?!
Array constants and named array constants seem to be interpretted differently when they are passed to and from the worksheet. I think this is to do with how they are structured within the memory. Excel is a black box and I am guessing, so I could most certainly be wrong.
If we set up a named array constant, which is really just a named formula, in the workbook:
Named array constant: My_Array ={3,5}
Firstly, it seems that a named array constant is NOT an array type.
We can see this with a couple of formulas, entered normally:
=TYPE({3,5}) returns 64 --> array type
=TYPE(My_Array) returns 1 --> not an array type. Returns 1 because the first element of My_Array is a double.
Simple as this is, as far as I am aware - and I have looked around - this is not actually documented anywhere? Maybe I'm missing something here?
Does this matter? Yes, it does - to me, at least. It means that calculations on array constants and named array constants work differently - they need to be treated as two separate animals.
=SUM({3,5}+1) returns 10
=SUM(My_Array+1) returns 4
=SUM({3,5})+1 returns 9
=SUM(My_Array) +1 returns 9
Evaluating the formulas 1 and 2 with F9 shows exactly the same thing, but the results are different? It seems that this is because only the first element of the named array is passed back for SUM to aggregate?
This is further supported by what happens if we deliberately convert My_Array into an array type. It seems there are three ways we can do this.
1. Use CTRL+SHIFT+ENTER:
=SUM(My_Array+1) returns 10 when CTRL+SHIFT+ENTERED
2. Use Sumproduct, which convertes its arguments into array types:
=SUMPRODUCT(My_Array+1) returns 10
3. Use the N() worksheet function:
=SUM(N(My_Array)+1) returns 10
Now the third one, using the N() worksheet function, is bizarre - to me, at least. Again, I can't find it documented anywhere that the N() worksheet function can do this? Perhaps it has a use after all!?
So, getting back to array constants and the memory. Looking at these results, it would make sense to me that a named array constant has to pass through a particular layer of interpretation that an array constant doesn't have to; or, at least to say that they are dimensioned somewhat differently in the memory?
The three ways we can induce Excel to calculate on array constants and named array constants in the same way suggests to me that when we CTRL+SHIFT+ENTER a formula, we are just converting the relevant parts, such as range reference values, of that formula into array types. So, in turn, an array formula should simply be defined as a formula that contains an array type. This means that array formulas are not just CSE formulas, and any formula that uses Sumproduct, an array constant, or another array type construct, is in fact an array formula. A formula that contains a named array constant is not an array formula unless there is an array type conversion in there. Again, looking around the internet, there are plenty of array formula tutorials that describe array formulas and what they do, but none of them seem to specifically define what an array formula is.
All thoughts, possibilities and suggestions are welcome?
Cheers,
Colin