If Week 1
is in A1 of both sheets, 1
is in A2 of a worksheet
etc then this might suit in B1 of another
:
=index(a!$A:$D,2,match($A1,a!1:1,0))
copied across to C1 and the 2
there replaced by 3
.
By default, vlookup
assumes the data is sorted, and finds the largest element that is less than or equal to the search key. Therefore, you should fill the table with the lower bound for each range:
+-------+--------+-------+---------+
| Minor | Normal | Major | Item |
| 1 | 1 | 1 | Arrow |
| 5 | 11 | 11 | Weapons |
| 10 | 21 | 21 | Potion |
| 45 | 32 | 26 | Ring |
+-------+--------+-------+---------+
Let's say the above is your range B2:E6. The first step is to filter the columns, so that only two are left: one of the first three, and the last one. For this I would use filter
based on regexmatch
:
=filter(B2:E6, regexmatch(B2:E2, "^("&A1&"|Item)$"))
For example, if A1 has "Normal" (my favorite mode) then the regular expression is "^(Normal|Item)$" which matches either of two words, and nothing else. So, if we don't do anything else, the result is
+--------+---------+
| Normal | Item |
| 1 | Arrow |
| 11 | Weapons |
| 21 | Potion |
| 32 | Ring |
+--------+---------+
But of course we don't stop here: the filtered columns should be fed into vlookup
:
=vlookup(A2, filter(B2:E6, regexmatch(B2:E2, "^("&A1&"|Item)$")), 2)
And that is the formula you want. For example, if A2 is 15, then the largest entry that is <=A2 is 11, so the returned value is "Weapons".
Best Answer
This is more a workaround than a real solution, but add this to the scripteditor and change to sheet name..
Since I do not know how to work with a star symbol (char) in GAS, the script writes a formula to the edited cell (in col G) which replaces the number that is typed in with that number of stars.