Using a number in a cell to generate a cell reference - excel

What I want to do might be better achieved with a database, however I have very limited experience with them, and only have to change the information infrequently.
What I have is a sheet where each row has 8 cells of relevant data.
What I want to do in another sheet is to enter a number into 1 cell, and have a group of cells below use that number to reference data in the other sheet.
For example, in Sheet1 I could have the following (fig 1):
| A | B | C | D | E | F | G | H
-----+-----+-----+-----+-----+-----+-----+-----+-----
101 | Dep | 700 | Sta | 100 | Sta | 300 | Dep | 900
What I want to achieve in sheet 2, by typing the row number into 1 cell, is to have the data in those 8 cells copied below, for example (fig 2):
| A | B | C | D |
-----+-----+-----+-----+-----+
1 | "Row Number" |
-----+-----+-----+-----+-----+
2 | =A# | =B# | =D# | =C# |
-----+-----+-----+-----+-----+
3 | =E# | =F# | =H# | =G# |
-----+-----+-----+-----+-----+
And yes, I am aware those formulae above do not reference the other sheet - this was to save space.
Which, if using the example row above, should look like this (fig 3):
| A | B | C | D |
-----+-----+-----+-----+-----+
1 | 101 |
-----+-----+-----+-----+-----+
2 | Dep | 700 | 100 | Sta |
-----+-----+-----+-----+-----+
3 | Sta | 300 | 900 | Dep |
-----+-----+-----+-----+-----+
So, in that example above (fig 3), what do I need to put in as a formula in cells A2-D2 & A3-D3 to automatically use the number in A1 as part of the cell reference to print the data from the other sheet.
Does that make sense? I hope so because I have over 300 lines to enter into my 1st sheet and another 70 lines x 7 blocks of columns on the second sheet.
Lastly I just want to say I want to avoid programming languages, like VBA, wherever possible.

Check out the INDIRECT() function.
For cell A2 in your example on the second sheet, enter:
=INDIRECT("Sheet1!"&"A"&$A$1)
Expand this formula to the apply to other target cells by changing the "&"A" portion to reference columns B, C, D, etc. from Sheet1 as needed in your grid per the following example:
=INDIRECT("Sheet1!"&"B"&$A$1)
=INDIRECT("Sheet1!"&"C"&$A$1)
=INDIRECT("Sheet1!"&"D"&$A$1)
These formulas will reference your selected "Row Number" in cell A1 and pull the related data from Sheet1 into Sheet2.

You can do this using the INDIRECT function
Returns the reference specified by a text string.
References are immediately evaluated to display their contents.
Use INDIRECT when you want to change the reference to a cell within a
formula without changing the formula itself.
http://office.microsoft.com/en-gb/excel-help/indirect-HP005209139.aspx

Related

Excel Formula INDEX+AGREGATE+ORDER by another column

I have an excel formula that I need help with, since I'm not that savvy on excel.
The formula is the following:
=IFERROR(INDEX(Liste!$C$2:$N$10000,AGGREGATE(15,6,(ROW(Liste!$A$2:$A$10000)-ROW(Liste!$A$2)+1)/ISNUMBER(SEARCH("BOX"," " & Liste!$B$2:$B$10000 & " ")),ROWS($A$4:$A4)),COLUMN()-1),"")
This formula looks on another sheet (Liste) for lines containing the word BOX on column B and show them on "ROWS($D$4:$D4)" (in this case) starting from Column "C".
I'm not even sure if that formula orders the results on column "B" since they're all the same with the word "BOX".
It works prefectly, the only think I can't achieve (and I've tried diferent combinations) is to change that code to make it show the results in order according to column "C" (not column B).
Sample Data:
Sheet "Liste"
|-----------|----------|-----------|
| B | C | D |
|-----------|----------|-----------|
| NOTBOX | 5 | SAMPLE |
| BOX | 3 | SAMPLE |
| BOX | 1 | SAMPLE |
| BOX | 2 | SAMPLE |
| NOTBOX | 4 | SAMPLE |
|-----------|----------|-----------|
Current Result:
|-----------|----------|
| A | B |
|-----------|----------|
| 3 | SAMPLE |
| 1 | SAMPLE |
| 2 | SAMPLE |
|-----------|----------|
Desired Result:
|-----------|----------|
| A | B |
|-----------|----------|
| 1 | SAMPLE |
| 2 | SAMPLE |
| 3 | SAMPLE |
|-----------|----------|
Can someone give me a hand?
One thing I forgot to state is that I need to drag this formula around (rows and columns) so it's important that I can drag it on a large zone (if lines are added in the future) and that it ignores the errors (blank).
Thank you in advance
Here is an example on how you could do this:
Formula in F2:
=SMALL(IF($A$2:$A$6=$E$2,$B$2:$B$6,""),ROW(A1))
Or in French
=PETITE.VALEUR(SI($A$2:$A$6=$E$2;$B$2:$B$6;"");LIGNE(A1))
Formula in G2:
=INDEX($C$2:$C$6,MATCH(F2,$B$2:$B$6,0))
Or in French
=INDEX($C$2:$C$6;EQUIV(F2;$B$2:$B$6;0))
Note: The first formula is an array formula and need to be confirmed through CtrlShiftEnter.
Drag them both down and include an IFERROR if you drag these formula's down and you don't want to see errors once there are no more hits.

Conditional formatting based on largest value in range of cells

I have an Excel sheet with a count of user logons at 3 different sites. I want to conditionally format a column (E) to output the location, based on the largest value in cell range columns B to D, example:
A | B | C | D | E
Name | Site1Logins | Site2Logins | Site3Logins | MainSite?
User1 | 200 | 0 | 50 | Site1
User2 | 0 | 20 | 120 | Site3
User3 | 10 | 80 | 40 | Site2
So, E should automatically populate the site based on the largest value of columns B, C & D. Is this possible?
Thank you.
What you are after isn't conditional formatting - that would be changing the Format of a cell rather than it's value.
A formula that would work for this task is:
="Site"&MATCH(MAX(B2:D2),B2:D2,0)
Though there are many ways in which you could achieve this

Excel or Google forms - How to identify a specific cell on a table and update value from another worksheet data

I have 2 work sheets. Sheet 2 has a table to be updated by the data from Sheet1. Sheet 2 first row has dates from today to 31 days and First column has names. Sheet1 has data columns of, Name, Shift (Give away, Swap, Delete, Take), Date, Letter( Which gives a letter as per Shift column entry. G - Give away, S- Swap, D- Delete, A - Take). What I need is a formula or a script to update Sheet2 by identifying the particular cell on sheet 2 by name and date from the Sheet 1 and enter the value from Letter column.
Sheet 1
Name | Shift.....| Date....| Letter..|
Mark | Swap | 02/AUG | S |
Ivon | Give away | 25/ AUG | G |
Laura| Take | 01/AUG | A |
Ann | Take | 02/AUG | A |
Ann | Give away | 03/AUG | G |
Sheet 2
|Name|01/AUG| 02/AUG | 03/AUG|....| 25AUG|
Laura| A | < - if Laura has is available to Take a shift on 01AUG
Mark | |
Ann | | A | G | <- If Ann has is available to Take a shift on 02AUG and Give away shift on 03AUG
Ivon |
The formula you want is something like this:
=IFERROR(INDEX(Sheet1!$D$2:$D$6,MATCH(1,INDEX(($A2=Sheet1!$A$2:$A$6)*(Sheet1!$C$2:$C$6=B$1),),0)),"")
Put this in B2 copy over and down.

Return array of all matches between two ranges

Ok so I am trying to take a common tutorial array formula a step further but cannot figure out how.
Essentially I have a set of sheets with values like below:
| Sheet 1 || Sheet 2 |
| Products(1) | Product Group || Products(2) | Data |
| | || | |
| 100 | 1 || 100 | abc |
| 200 | 2 || 200 | def |
| 300 | 3 || 200 | ghi |
| 400 | 3 || 500 | jkl |
| 500 | 2 || 400 | mno |
Sheet 1 lists all parameters that classify each product and uses those to assign each product to a group. Essentially Products is a unique index key.
Sheet 2 is a tracking list of every time that a product is run, how it did. Therefore product numbers may show up multiple times or not at all.
I have a third sheet in which a product number is entered, from that its group number is calculated, and sheet 1 is searched for all products with that group number and the list is returned using an array formula (using this tutorial http://thinketg.com/how-to-return-multiple-match-values-in-excel-using-index-match-or-vlookup/ which shows up all over on line by different people). We will call this "Column K" on Sheet 3.
What I want to do now is take it a step further and return "Data" from Sheet 2 for all matches between "Sheet 2"!"Products(2)" and "Sheet 3"!"Column K". If "Column K" was fixed I could use the same formula again and put an OR statement into the IF expression, but because K is dynamically populated I am not sure how to find them all.
For clarification, The end result that I would ideally show is like this:
| Sheet 3 |
| Product Num | Column K | Column L | Column M |
| (user enters) | (automatic) | (automatic) | (automatic) |
| 500 | 200 | 200 | def |
| | 500 | 200 | ghi |
| Product Group | | 500 | jkl |
| (automatic) | | | |
| 2 | | | |
If you compare a column vector with an row vector in an array formula then it will compare each value from the column with each value in the row. So the following will work because we transpose the values in Sheet3!K1:K[n] into a row vector before comparing with Sheet2!$A$1:$A$10000.
Sheet1:
Sheet2:
Sheet3:
Formulas in Sheet3:
In A5:
=VLOOKUP($A$2,Sheet1!$A:$B,2,FALSE)
In K2 downwards:
{=IFERROR(INDEX(Sheet1!$A$1:$A$10000,SMALL(IF(Sheet1!$B$1:$B$10000=$A$5,ROW(Sheet1!$B$1:$B$10000)),ROW(1:1))),"")}
In L2 downwards:
{=INDEX(Sheet2!$A$1:$A$10000,SMALL(IF(Sheet2!$A$1:$A$10000=TRANSPOSE($K$1:INDEX($K:$K,MAX(IF($K$1:$K$10000<>"",ROW($K$1:$K$10000))))),ROW(Sheet2!$A$1:$A$10000)),ROW(1:1)))}
In M2 downwards:
{=INDEX(Sheet2!$B$1:$B$10000,SMALL(IF(Sheet2!$A$1:$A$10000=TRANSPOSE($K$1:INDEX($K:$K,MAX(IF($K$1:$K$10000<>"",ROW($K$1:$K$10000))))),ROW(Sheet2!$A$1:$A$10000)),ROW(1:1)))}
Formulas in K2,L2,M2 are array formulas. Input them without the curly brackets and then press [Ctrl]+[Shift]+[Enter].
The reference to K[n] in Sheet3!K1:K[n] is computed with
INDEX($K:$K,MAX(IF($K$1:$K$10000<>"",ROW($K$1:$K$10000))))
therein the
MAX(IF($K$1:$K$10000<>"",ROW($K$1:$K$10000)))
gets the largest row number in column K where the content not equals "".
If the product numbers are ever numeric, then it is easier and it will be possible to have the results sorted also.
Sheet1 and sheet2 see above.
Sheet3:
Formulas in Sheet3:
In A5: see above
In K2 downwards:
{=IFERROR(SMALL(IF(Sheet1!$B$2:$B$10000=$A$5,Sheet1!$A$2:$A$10000),ROW(1:1)),"")}
In L2 downwards:
{=SMALL(IF(Sheet2!$A$2:$A$10000=TRANSPOSE($K$2:INDEX($K:$K,MATCH(MAX($K:$K),$K:$K))),Sheet2!$A$2:$A$10000),ROW(1:1))}
In M2 downwards:
{=INDEX(Sheet2!$B$1:$B$10000,SMALL(IF(Sheet2!$A$1:$A$10000=$L2,ROW(Sheet2!$A$1:$A$10000)),COUNTIF($L$2:$L2,L2)))}

Excel Formula Optimisation

I am no excel expert and after some research have come up with this formula to look at two sets of the same data from different times. It then displays new entries that are in the latest list of data but not in the old list.
This is my formula:
{=IF(ROWS(L$4:L8)<=(SUMPRODUCT(--ISNA(MATCH($E$1:$E$2500,List1!$E$1:$E$2500,0)))),
INDEX(E$1:E$2500,
SMALL(IF(ISNA(MATCH($E$1:$E$2500&$F$1:$F$2500,List1!$E$1:$E$2500&List1!$F$1:$F$2500,0)),
ROW($F$1:$F$2500)-ROW($F$1)+1),ROWS(L$4:L8))),"")}
Are there any optimisation techniques I could employ to speed up the calculation?
As requested
Some example data(link to a spreadsheet):
https://docs.google.com/file/d/0B186C84TADzrMlpmelJoRHN2TVU/edit?usp=sharing
On this scaled down version its more efficent but on my actual sheet with a lot more data it is slowed.
Well, I was playing around a bit and I think that this works the same, and without the first IF statement:
=IFERROR(INDEX(A$1:A$2500,SMALL(IF(ISNA(MATCH($A$1:$A$2500&$B$1:$B$2500,List1!$A$1:$A$2500&List1!$B$1:$B$2500,0)),ROW($B$1:$B$2500)-ROW($B$1)+1),ROWS(F$2:F2))),"")
That part in your sample data:
ROWS(F$2:F2)<=(SUMPRODUCT(--ISNA(MATCH($A$1:$A$2500,List1!$A$1:$A$2500,0))))
As I understood it, it only sees to it that the row number in which the formula is entered is lower than the number of 'new' items, but it doesn't serve any purpose because when you drag the formula more than required, you still get errors instead of the expected blank. So I thought it could be removed altogether (after trying to substitute it with COUNTA() instead) and use an IFERROR() on the part directly fetching the details.
EDIT: Scratched that out. See barry houdini's comment for the importance of those parts.
Next, you had this:
ROW($B$1:$B$2500)-ROW($B$1)+1
-ROW($B$1)+1 always returns 0, so I didn't find any use to it and removed it altogether.
It's still quite long and takes some time I guess, but I believe it should be faster than previously by a notch :)
A relatively fast solution is to add a multi-cell array formula in a column alongside List 2
{=MATCH($A$1:$A$16,List1!$A$1:$A$11,0)}
and filter the resultant output for #N/A.
(Or see Compare.Lists vs VLOOKUP for my commercial solution)
Array formula is slow. When you have thousands of array formula, it will make the speed very slow. Thus the key will be to avoid any array formula.
The following will be my way to achieve it, using only simple formula. It should be fast enough if you only have 2500 rows.
Column F and H are "Keys", created by concatenating your 2 columns (E and F in your original formula)
Assuming the first line of data is on row 3.
Data:
| A | B | | D | E | F | | H |
| index | final value | | ID | exist in Old? | Key (New) | | Key (Old) |
--------------------------------------------------------------------------------
| 1 | XXX-33 | | 0 | 3 | OOD-06 | | OOC-01 |
| 2 | ZZZ-66 | | 0 | 1 | OOC-01 | | OOC-02 |
| 3 | ZZZ-77 | | 1 | N/A | XXX-33 | | OOD-06 |
| 4 | | | 1 | 4 | OOE-01 | | OOE-01 |
| 5 | | | 1 | 2 | OOC-02 | | OOF-03 |
| 6 | | | 2 | N/A | ZZZ-66 | | |
| 7 | | | 3 | N/A | ZZZ-77 | | |
Column E "exist in Old?": test if the new key (Column F) exists in the old list (Column H)
=MATCH(F3, $H$3:$H$2500, 0)
Column D "ID": to increment by one whenever a new item is found
=IF(ISNA(E3), 1, 0)+IF(ISNUMBER(D2), D2, 0)
the 2nd part of ISNUMBER is just for the first row, where just using D2 can cause an error
Column A "index": just a plain series starting from 1 (until the length of new list Column F)
Column B "final value": to find the new key by matching column A to Column D.
=IF(A3>MAX($D$3:$D$2500), "", INDEX($F$3:$F$2500, MATCH(A3, $D$3:$D$2500, 0))
This column B will be the list you want.
If it is still too slow, there exists some dirty tricks to speed up the calculation, e.g. by utilizing a sorted list with MATCH( , , 1) instead of MATCH( , , 0).

Resources