Assuming you "get" the Named Range bit in the prior post we can move on to the formula itself on sheet "Main".
Mods: I am using Code tags for non-code purely for presentational purposes
Before continuing I would make the following points:
AIM OF FORMULA
The aim of the formula is to generate an ID "Number" based upon the "Choices" made by the end user for each given "Option".
The "size" of the number is determined by the number of "Options" listed in Row1 on Options sheet.
That is to say if we have 4 options to choose from the resulting value should be 4 digits in length (eg 1111), if there were 5 "options" the resulting value should be 5 digits in length (eg 11111) etc...
The digits themselves represent the Index position of the "Choice" within the parent list.
So if for "Option 1" the user selects the first listed value in the resulting validation list the digit used in the number should be 1, were the end user were to choose the 4th "Choice" from the validation list the digit should be 4 etc...
The ordering of the digits in the resulting number is ordered based upon the order of the Options list.
ie the option listed in B1 on Options shall dictate the first digit in our number, the last option listed in row 1 shall generate the last digit in our number... the ordering of the options on sheet "Main" is on this basis not important... it is the order in row 1 on Options that is the predetermining factor.
So we have:
=SUMPRODUCT((ISNUMBER(MATCH(_OptionsTbl,$C$2:$C$11,0)))*ROW(INDIRECT("1:"&ROWS(_OptionsTbl)))*10^((C OLUMNS(_OptionsTbl)-COLUMN(INDIRECT("A1:"&ADDRESS(1,COLUMNS(_OptionsTbl)))))))
This looks worse than it is ...
Firstly we want to validate the Choices made in C to ensure they can be found in our DNR (_OptionsTbl)
We then want to multiply that by the Row being iterated (at which point the Boolean return of TRUE/FALSE will be coerced to Integer equivalent of 1/0 respectively)...
To get the ROW being iterated we can use:
Breaking the above down further...
ROWS:
if our DNR refers to Options!B3:F6 then it follows that ROWS(_OptionsTbl) will return 4 as there are 4 rows within that range, namely rows 3,4,5 & 6
INDIRECT:
The INDIRECT will generates a reference to 1:4
ROW:
As we iterate the INDIRECT reference ROW will in turn generate {1,2,3,4}
So at this point we have
(Booleans)*({1,2,3,4}) ... which is essentially returning for us the INDEX positions of the "Choices" made...
If we consider the sample file where the "Choices" index positions were:
If at this point we executed just:
The result would be 9 ...
However this will not work for us as the value we want to generate is in fact:
11214 -- ie 11,214
So we must take the index position and multiply by 10 ^ x ... eg
which if analysed further becomes
which if analysed further becomes
which gives us 11214 ... this method is provided for us by Ron C.
We know from your prior post we can get the result for 5 "Option" setup using:
However we want the { } to be variable given we want to vary the number of columns we have... if we had 6 columns we would need 10^5 down to 10^0 ... if we had only 2 columns we would simply want 10^1 to 10^0 ....
Given we know that this calculation is tied directly to the no. of "Options" we have (ie columns in our DNR) we can use that info to generate this calculation:
We can ignore the 10^ as this is fixed ... what varies as we iterate is the power be it 4 -> 0, 5 -> 0 etc etc...
COLUMNS(_OptionsTbl) will work like ROWS but return for us the number of COLUMNS present in our range... in our case we have 5 Columns (B3:F6)
We know that the power should decrease as we iterate... ie first digit is to to be the biggest & last digit the smallest ... so we use in short the COLUMNS value and subtract from it with each iteration, eg:
so as to generate:
this will in turn generate
To analyse this part further
Working backwards
will return a reference in traditional notation, eg:
So we use ADDRESS to generate for us a reference based on the number of columns in our DNR (5), using the example:
We then use INDIRECT as before to create a Range through which we can iterate:
We use COLUMN as we did ROW before to return for us the COLUMN number of those cells as they are iterated:
Thus we get our
And we have our formula...
PHEW...
I'm not maths whizz so the terminology I've used may be incorrect, apologies, hopefully someone will correct me where I've used terms inaccurately.
Bookmarks