excel reference to another work book multiple sheets - excel-formula

I am trying to use a formula that would let me copy and paste it down so I dont have to link every-time
The source workbook has tabs named 1,2,3,4,5.....100
I want to use simple formula ='[test.xlsx]1'!$O$117
but I want to replace ='[test.xlsx]**A1**'!$O$117
so it is dynamic and I can copy it down
='[test.xlsx]B1'!$O$117; where B1 = 2
='[test.xlsx]C1'!$O$117; where C1 = 3
I tried ='[SCD PCAP 2Q15 - waterfall.xlsx]&1&'!$O$117
any ideas?

You can do so by Two step process.
Step 1 (Thanks to #Excel Hero for this answer)
1
Open the Name Manager. Control-F3 from the worksheet, and then click the New button.
2
For the Name field in the dialog, enter EVALXFD. I just picked this name it is using column XFD in it. But you can pick whatever name you like.
3
For the Refers to field, enter this
=EVALUATE($XFD1)
4
Click OK and then Close.
Step 2
Paste below mentioned formula in last helper column XFD (I am assuming you are not using this column)
=CONCATENATE("='[Test.xlsx]",$A1,"'!$A$1")
In B1 enter this formula and drag it down:
=EVALXFD
That's it.

Use the INDIRECT() function. E.g., with $A$1 = 2, $A$2 = 3, ..., you can use
=INDIRECT("'[test.xlsx]"&B1&"'!$O$117")
which Excel will concatenate =INDIRECT('[test.xlsx]2'!$O$117) and then evaluate.
Note also that I've written the references above based on copying the formula down column B (with references in column A), so the row number will change, but the reference will always be to column A.

Related

Using Index Match between two sheets in excel

I have two sheets.
This is the first sheet. Named 3
And this is the second sheet. Named centralizare
I have to write in Sheet2 C5 the number of 'Id garantie' from Sheet1 if the 'Categorie' from Sheet1 is 'Done' (Sheet2 B5) and 'Status 1'from Sheet1 is 'In lucru' (Sheet 2 B4)
I tried this
=COUNT(INDEX('3'!$C$2:$C$99,MATCH(B5,'3'!A2:A99,0)))
but it returns only one number if only the 'Categorie' is Done.
And other method with errors
=MATCH('3'!C2:C99,(centralizare!C5='3'!B2:B96)*(D4='3'!F2:F96),0)
=INDEX('3'!$C$2:$C$99,MATCH(D5,'3'!C2:C99,0))
=COUNT(INDEX('3'!A2:A96, MATCH("In lucru",'3'!E2:E96)))
You could try an array formula with sumproduct:
=SUMPRODUCT(--IFERROR((('3'!A2:A5=centralizare!B5)),0))
Must be entered using ctrl + alt + enter. Is should appear like so in your formula bar if done right:
{=SUMPRODUCT(--IFERROR((('3'!A2:A5=centralizare!B5)),0))}
Sample workbook: https://filetea.me/t1sjZdwkvxrRxGePZmKZyB7BQ
EDIT: It also seems that you should never had "finalizat" & "wip" in the same row, if I understand your rules right. WIth the array formula, you can check for both rules & only count those that meet both rules, not just one, and somewhat check data quality this way.:
{=SUMPRODUCT(--IFERROR((('3'!A2:A5=centralizare!B5))*('3'!C2:C5=***choose a cell/range where you put a reference to finalizat/in luru instead of wip/donw***),0))}
In other words, the general format for multiple criterial is:
{=SUMPRODUCT(--IFERROR(((CRITERIA ONE)*(CRITERIA TWO)),0))}

referencing sheets by number instead of name in cells

Lets say
sheet3.name = "d"
Is there a way I could put in a cell on sheet2 the formula =sum(sheet3!b:b) where sheet3 is being substituted with the actual sheet3 name?
I can only get =sum('d'!b:b) to work so far.
I could use VBA for this probably but I'm curious how to do this in a cell so I don't have to run a macro each time.
If you can use a UDF User Defined Function that will return the sheet name
Function SHEETNAME(number As Long) As String
SHEETNAME = Sheets(number).Name
End Function
then a formula like
=SUM(INDIRECT(SHEETNAME(3) &"!B:B"))
will return the sum from column B on sheet 3.
SHEETNAME(number) returns the sheet name of the number which is index.
So Sheet(1) returns Sheet1, etc
Use below formula anywhere in the sheet to get the sheet name - the sheet must have a filename for this to work:
=REPLACE(CELL("filename"),1,FIND("]",CELL("filename")),"")
You can either reference that cell using Indirect:
=SUM(Indirect("'"&A1&"'!B:B"))
or, if you don't want to have a second cell, you can combine the two formulas into one:
=SUM(INDIRECT("'"&REPLACE(CELL("filename"),1,FIND("]",CELL("filename")),"")&"'!B:B"))
For anyone not concerned with the order of the sheets, the post by Biff here on mrexcel.com works well.
In Excel 2013, go to the Formulas tab in the ribbon and make a defined name:
Name: SheetNames
Refers to: =GET.WORKBOOK(1)&T(NOW())
Then use a formula like this example:
=INDIRECT("'"&INDEX(MID(SheetNames,FIND("]",SheetNames)+1,255),A3)&"'!A1")
where A3 refers to the index number in a cell in the current sheet, and A1 refers to the location of the value to be retrieved from the other sheet. I.e., in the current sheet, if A3 = 2, then the formula will point to cell A1 in the second sheet of the workbook. I just use a column of index numbers in my current sheet, then drag this formula down and it fills in values from all of my other sheets.
You will need to save as a macro-enabled file (.xlsm).
I'm not sure if this is a good idea but it's the first one I could think of.
I would add additional function to your VBA project which will return actual name of your Sheet3:
Function Sheet3Name()
Sheet3Name = Sheet3.Name
End Function
Next, when you create sum formula of column B:B in Excel cell you need to do it in this way:
=SUM(INDIRECT(Sheet3Name()&"!A:A"))

Unsure of how to use cell data to get data from another worksheet

This is a weird sort of function that I've never tried to use before, so I'm not sure how to go about asking without using an example.
Essentially, I have a column of strings that represent datasheets in this .xls file. Each row has data in it that corresponds to the datasheet named in said column. In case my explanation is insufficient, here's an example:
Worksheet 1 : Worksheet 1 Value 1 : Worksheet 1 Value 2 : .......
Worksheet 2 : Worksheet 2 Value 1 : Worksheet 2 Value 2 : .......
etc...
At the moment, the spreadsheet requires you to manually update the worksheet reference for each column to populate the data, i.e. for every cell, I need to manually fill out the worksheet name in this equation:
='Worksheet 1'!B111
This works, but is obviously suboptimal, as I have a large number of worksheets. What I WANT to do is be able to do is be able to fill out Cell 1 (the worksheet name) and have every other cell use the worksheet name as its reference, like so:
Column A : Column B : Column C : ...
"Worksheet 1" : =A1!B111 : =A1!B34 : ...
"Worksheet 2" : =A2!B111 : =A2!B34 : ...
First question: Is this possible?
Second quesion: How?
Sorry if this has been answered already, but I could barely figure out how to ask the question in the first place.
You can use the INDIRECT() function. With the text Worksheet 1 in cell A1 you can use
=indirect("'"&$A1&"'!B111")
Since the sheet name can contain spaces, you need to start the text of the Indirect with a single quote, append the cell with the sheet name, then append the closing single quote, the exclamation mard and finally the cell reference.
If all cells in column A refer to B111, just copy the formula down and change the sheet name in column A. Copy the formula across and adjust the cell reference for B111 to whatever is desired before copying down.
If you want to pre-populate a worksheet with these values, fire up the macro recorder, create a new sheet, go to an existing sheet and copy and paste everything into the new sheet, then stop the macro recorder. That will give you a starting point for the code you need.

Add common prefix to all cells in Excel

I have a column with some text in each cell.
I want to add some text, for example "X", at the start of all cells. For example:
A B
----- >>>> ----
1 X1
2 X2
3 X3
What is the easiest way to do this?
Type this in cell B1, and copy down...
="X"&A1
This would also work:
=CONCATENATE("X",A1)
And here's one of many ways to do this in VBA (Disclaimer: I don't code in VBA very often!):
Sub AddX()
Dim i As Long
With ActiveSheet
For i = 1 To .Range("A65536").End(xlUp).Row Step 1
.Cells(i, 2).Value = "X" & Trim(Str(.Cells(i, 1).Value))
Next i
End With
End Sub
Select the cell you want to be like this,
Go To Cell Properties (or CTRL 1)
under Number tab
in custom
enter
"X"#
Select the cell you want to be like this, go to cell properties (or CTRL 1) under Number tab in custom enter "X"#
Put a space between " and # if needed
Select the cell you want,
Go To Format Cells (or CTRL+1),
Select the "custom" Tab, enter your required format like : "X"#
use a space if needed.
for example, I needed to insert the word "Hours" beside my numbers and used this format : # "hours"
Enter the function of = CONCATENATE("X",A1) in one cell other than A say D
Click the Cell D1, and drag the fill handle across the range that you want to fill.All the cells should have been added the specific prefix text.
You can see the changes made to the repective cells.
Option 1:
select the cell(s), under formatting/number/custom formatting, type in
"BOB" General
now you have a prefix "BOB" next to numbers, dates, booleans, but not next to TEXTs
Option2:
As before, but use the following format
_ "BOB" #_
now you have a prefix BOB, this works even if the cell contained text
Cheers, Sudhi
Michael.. if its just for formatting then you can format the cell to append any value.
Just right click and select Format Cell on the context menu, select custom and then specify type as you wish... for above example it would be X0. Here 'X' is the prefix and 0 is the numeric after.
Hope this helps..
Cheers...
Go to Format Cells - Custom. Type the required format into the list first. To prefix "0" before the text characters in an Excel column, use the Format 0####. Remember, use the character "#" equal to the maximum number of digits in a cell of that column. For e.g., if there are 4 cells in a column with the entries - 123, 333, 5665, 7 - use the formula 0####. Reason - A single # refers to reference of just one digit.
Another way to do this:
Put your prefix in one column say column A in excel
Put the values to which you want to add prefix in another column say column B in excel
In Column C, use this formula;
"C1=A1&B1"
Copy all the values in column C and paste it again in the same selection but as values only.
Type a value in one cell (EX:B4 CELL). For temporary use this formula in other cell (once done delete it). =CONCAT(XY,B4) . click and drag till the value you need. Copy the whole column and right click paste only values (second option).
I tried and it's working as expected.

Excel spreadsheet

I need a way of displaying 3 cells of data.
For example
Cell 1 Cell 2 Cell 3
20 140 Lee
12 110 Kerrie
Whenever anyone's name is input in cell 3 I need a separate spreadsheet to display the name (cell 3) and the information in cells 1 & 2 (the information in cells 1 & 2 will always be different).
From your question it's unclear whether you're talking about a person's name input into a single cell (e.g., "C3") or somewhere in a given column (e.g., "C:C").
In the former case you can easily use Guiness's suggestion; or you can even more easily write a formula like this to concatenate the values in Cells 1 through 3 (supposing the worksheet is called "Sheet1"):
="Name = "&Sheet1!C3&": Cell1 = "&Sheet1!A3&", Cell2 = "&Sheet1!B3
(This is based on Cells 1 through 3 in your example being in columns A through C, and in row 3.)
On the other hand, if you're talking about the latter case and you want to run some VBA code whenever a new name is ADDED to column C, you can use the Worksheet_Change VBA function. If this is the case, edit the question to indicate that.
Say you have Excel workbook 1 called Book1.xls. Open that workbook and type the following in the first three rows and across first three columns
Row 1 - cell1 cell2 cell3
Row 2 - 20 12 Jee
Row 3 - 87 25 Kee
Now open the other Workbook - say Book2.xls. Select the cell in which you want to put the value. In that cell press "=" (the 'equals' sign)
Now this is the important bit. After pressing that 'equals' go back to the first excel workbook and select the cell, the content of which you want entered in the second workbook.
So, in this case, the cell in the second workbook will have a formula like this
=[Book1]Sheet1!$A$2
Do the same for the rest of the cells you want.
Important: Please note that the second workbook will not be filled unless the first workbook is opened also.
Use the function: VLOOKUP

Resources