Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using a number in a cell to generate a cell reference

Tags:

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.

like image 521
Escribblings Avatar asked Nov 15 '13 22:11

Escribblings


People also ask

How do you reference a cell based on a value in another cell?

Click the cell where you want to enter a reference to another cell. Type an equals (=) sign in the cell. Click the cell in the same worksheet you want to make a reference to, and the cell name is automatically entered after the equal sign. Press Enter to create the cell reference.

Can you use a variable to reference a cell in Excel?

A cell reference in Excel refers to the value of a different cell or cell range on the current worksheet or a different worksheet within the spreadsheet. A cell reference can be used as a variable in a formula.

How do I automatically generate reference numbers in Excel?

Unlike other Microsoft Office programs, Excel does not provide a button to number data automatically. But, you can easily add sequential numbers to rows of data by dragging the fill handle to fill a column with a series of numbers or by using the ROW function.

How do you reference a cell number?

A cell reference or cell address is a combination of a column letter and a row number that identifies a cell on a worksheet. For example, A1 refers to the cell at the intersection of column A and row 1; B2 refers to the second cell in column B, and so on.


2 Answers

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.

like image 151
Derrik Avatar answered Oct 21 '22 08:10

Derrik


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

like image 45
Sam Avatar answered Oct 21 '22 07:10

Sam