Dynamically referencing cells in other worksheets in Excel? - database

I have a table of data, a selection of which look like:
BARC 0.0001 0.0003 0.0006 0.0012 0.0009 0.0010 0.0008 0.0024
BNP 0.1915 4.1915 0.2314 0.3147 0.3168 0.3300 0.3060 0.4277
CSGN 0.1915 0.0003 0.2221 0.0104 0.0109 0.0124 0.0097 0.0152
The data in each cell are linked to a separate worksheet which share a name with the names in the first column. Each entry in the table for each column references the same cell but in a different worksheet. So B1 is BARC!G850, B2 is BNP!G850, and B3 IS CSGN!G850. The references are the same for each cell besides the worksheet name, but they don't increase incrementally across the rows; C1 IS BARC!G858 and D1 is BARC!G863, for example.
I want to use a formula to automatically populate the table instead of typing out the worksheet name references by hand. How can I do this?

Using the INDIRECT function you can reference a worksheet based on the text in ColA.
A | B | C
BARC | =INDIRECT( A1&"!G850") | =INDIRECT( A1&"!G858")
etc.

Use the formula =INDIRECT($A1 & "!G850") and copy that down column 1. For other columns you use the respective cell reference.
You can make it a bit more dynamic to include a row at the top in which you specify the exact cell reference to use in the formula for each column.
The formula should then read something like =INDIRECT($A1 & "!" & B$1)
This will allow you to simply copy the same formula to all cells and it will use the sheet name from the first column and the cell reference at the top to lookup the correct cell from the correct worksheet

Related

How can I keep references to changing spreadsheet constant?

I have 2 columns in a sheet that are referencing another dynamic sheet which has new rows added at the top all the time.
I want column A to be a copy of column A in Sheet1, so this works to put in cell A1:
={Sheet1!A:A}
However, I want column B to a formula applied to every row in column B of Sheet1. Problem is, when I put in a a formula, e.g.
=formula(B1)
then it changes to
=formula(B30)
when 29 new rows added
I want it to stay as B1, but it won't. If I use an absolute reference $B$1 then I can't copy the formula down the column.
Any wizards out there to help me out?
If you want to get the matching row from a column of another worksheet, then use INDEX and ROW, like so:
=FORMULA(INDEX(Sheet1!$B:$B, ROW(), 1))
This will always return the value in Column B of Sheet1, on the same Row as the formula is in on Sheet2 - even if you insert rows at the top of Sheet1
You can do "partially absolute reference" (I don't know the correct way of saying this).
You can lock only the column so would be =$A1 which means that it will never change the column but when you drag down the formula, it will change to =$A2, =$A3...
Or you can lock only the row typing =A$1 This way it will be locked on the row only.
You can do this also by pressing F4 several times: 1 time will lock both, the 2nd time will lock the row only, the 3rd time the column only and the 4th time will delete the locking.
the proper way would be to use INDIRECT like:
=INDIRECT("Sheet1!B1:B")

How do I Add Values from Worksheet 1 to Another Worksheet in the same Excel File according to an unique ID Nr?

I would like to retrieve average daily milk from sheet 1 to sheet 2. Each row has a unique identification number. The average daily milk data exported to sheet 2 is linked to the unique ID Nr. In sheet 1 there are many more unique ID.Nr ( Rows) present than in sheet 2. How do I transfer the data from sheet 1 to sheet 2 in exact correlation to identification nr, without sorting the rows?
I have tried vlookup function but result is always NA. I belive it should be an array function, as it has too look for ID Nr. and cannot use position of cell.
Table Sheet1 is on a different Worksheet than Sheet 2 but on same File.
Vlookup should work just fine. The only thing is that you have to make sure that the Id Nr. in both sheets are the same type (In this case both should be strings since they have "_" in the text). This is how you should use the vlookup:
=VLOOKUP(A2,Sheet1!A:B,2,FALSE)
And then copy the formula all the way down in column B of sheet2
The solution is to use the index match function. The advantage in comparison to an lookup function is that it handles great amount of data better and also the reference number does not need to be on the far left column.

Excel formula needed for a 2-D array lookup in separate worksheets

Is there a formula in Excel that will do a 2-D array lookup in separate worksheets inside a single workbook?
I have three tables formatted identically with different data in the tables. Each table is located in a separate worksheet.
Table 1: Carbon Steel Welding Man-hours (CS)
Table 2: Stainless Steel Welding Man-hours (SS)
Table 3: Aluminum Welding Man-hours (Al)
Note: y-axis: pipe diameter, x-axis: pipe schedule(thickness)
I want the formula to identify the material type (CS,SS,Al) in the "summary sheet", and use the correct "man-hour table" inside the correct worksheet. The formula must then perform a 2-D array lookup (y-axis: pipe diameter, x-axis: pipe schedule "thickness"), and display the correct data from the "man-hour table" in the "summary sheet".
To avoid the Volatile INDIRECT function, use a nested IF to lookup each sheet.
=IF(A5="CS",INDEX(CS!Table,MATCH(...),MATCH(...)),IF(A5="AL",INDEX(AL!Table,MATCH(...),MATCH(...)),IF(A5="SS",INDEX(SS!Table,MATCH(...),MATCH(...)),"")))
Note: Excel formula If is short circuited, so only one INDEX/MATCH will be executed
Use INDIRECT to return the correct sheet and INDEX/MATCH/MATCH to get the correct MH:
=INDEX(INDIRECT("'" & A5 &"'!A:X"),MATCH(B5,INDIRECT("'" & A5 &"'!A:A"),0),MATCH(C5,INDIRECT("'" & A5 &"'!5:5"),0))

excel assemble two sheets exported from database

I have two sheet of excel exported from a database with hundreds of rows.
In first sheet I've these columns
name age gender
id1 23 m
id2 45 f
In second sheet these columns
id1 john smith
id2 jean ford
I'm looking for a macro or somethig else to automatically replace the idx in first sheet with the corresponding values from second sheet.
The final result should be a sheet like:
name age gender
john smith 23 m
jean ford 45 f
You don't need anything as complicated as a macro-- VLOOKUP will suffice:
Searches for a value in the first column of a table array and returns
a value in the same row from another column in the table array.
The V in VLOOKUP stands for vertical. Use VLOOKUP instead of HLOOKUP
when your comparison values are located in a column to the left of the
data that you want to find.
For example, if your id-sheet mapping was on Sheet2, then the formula
=VLOOKUP(A2,Sheet2.$A$1:$B$2, 2)
would look for the value found in this sheet's A2 cell in the leftmost column of the data table located in Sheet2.$A$1:$B$2, and then return the value from the 2nd column of that table. Copy that downwards, and get something like

matching data from one worksheet column to another worksheet column

I have two worksheets that have two columns of data. In column A of the Worksheets are the name of an item and in column B are the price of the item. Worksheet 1 has the price from last year and worksheet 2 has price from this year. The names of items in Worksheet 1 may or may not be in Worksheet 2.
I need a process that will match the names in each worksheet and if there is a match determine the price differential for that item. The price differential will go in column C in worksheet 2.
I have considered using an if-then function with a vlookup function but, I need to check for a match in all columns A from worksheet 1 and worksheet 2 for all the records. I believe a VB looping process may be more efficient.
Since it would appear to me you are only likely to require this once (or once a year) efficiency does not seem to be very significant, so formulae may serve.
Assuming labels (respectively: Item_Name and Price_O in Sheet1, Item_Name, Price_N and Diff in Sheet2) in Row1 then the following formulae (copied down to suit) should indicate where there is no match (with #N/A or, if there is, the price change relative to last year:
In Sheet1 C2: =IF(MATCH(A2,Sheet2!A:A,0)>0,"")
In Sheet2 C2: =B2-VLOOKUP(A2,Sheet1!A:B,2,FALSE)
Alternatively, a pivot table might provide a better overview, in combination with:
In Sheet2 H5: =IF(OR(ISBLANK(F5),ISBLANK(G5)),"No Match",G5-F5) (copied down to suit).
In Sheet2 E1 call up the PivotTable wizard (Alt+D, P if required) , select Multiple consolidation ranges and PivotTable, Next.
Select I will create the page fields, Next.
In Range select or insert Sheet1!$A:$B, Add, then Sheet2!$A$B, Add, Next, select Existing worksheet and enter =$E$3, Finish.
Right click on table and if necessary change Σ Values from Count of Value to Sum of Value (by left clicking on Count of Value, left clicking on Value Field Settings… and selecting Sum in Summarize by), OK.
Right click on the table, left click on PivotTable Options, left click on Totals & Filters and if necessary untick Show grand totals for rows, OK.
If necessary, right click on PriceN in the table, Sort, Sort Z-A.

Resources