How to get sheet name using formula excel 2007 - excel

I am trying to get excel 2007 sheet name in a cell of that sheet using formula. I tried to Google and found this:
=MID(CELL("filename",A1),FIND("]",CELL("filename",A1))+1,255)
But that does not work for excel 2007.
CELL("filename";A1)
Works but it gets the whole path.
My question is is there a way to get only a sheet name?

You can use the following formula:
=RIGHT(CELL("filename"),LEN(CELL("filename"))-FIND("]",CELL("filename")))
* Workbook must be saved first!
The formula is doing this:
RIGHT will return the characters after a numerical amount of characters in a string.
LEN returns the number of characters in a string.
FIND returns a number based on where a string is found within a string.
So all in all, the formula is saying take away the place that the first found ] is within the filename from the total length of the filename. We then just need the right hand portion of the filename after the numerical value we've just calculated.

You can "translate" 2010 formula to 2007:
=MID(CELL("filename";A1);FIND("]";CELL("filename";A1);1)+1;LEN(CELL("filename";A1)))
You may thing shorter way but that one works well.

Related

Unable to convert text to Numbers

I've been given an excel to import on Database, it was exported from an Access DB. in the excel there's a column type_class, in one excel it's good(sheet1), but on another excel which I moved to sheet2 to make VLOOKUP function, I can't tell whether it's a text or a number column from the first sight. the upper-left green-thing is not showing on all cells. but, using ISTEXT function result in text. below is the original column without any changes or formatting, as well as ISTEXT result.
when I use the column in a VLOOKUB function to transfer the Name to the first sheet, only (1010, 1101, 1102,....), hence the cells with the green-mark on the upper-left corner.
I can easly format the key in sheet1 using text-to-columns, cell formatting, and any other way.
but I cannot change the column in sheet2, I tried:
Text-to-Columns
Cell Formatting
VALUE(text), CLEAN(text), TRIM(text), TRIM(CLEAN(text)), CLEAN(SUBSTITUTE())
Multiply by 1
but only the cell with the green-mark changes to a number, the rest stays the same. I browsed the internet but didn't get a solution either.
Edit:
I uploaded what is need to test the case on the drive. you can find it here
Help Appreciated
For your digit strings that you can't convert to text, from the comments it seems there are extra characters in that string not removable by TRIM or CLEAN.
Determine what those character are
Assume a "non-convertible" digit string is in A1
Enter the following formula
B1: =MID($A$1,ROWS($1:1),1) and fill down
C1: = UNICODE(B1) and fill down
From this you can determine the character to use in a SUBSTITUTE function.
For example:
From the above we see that the character code that we need to get rid of is 160.
So we use:
=SUBSTITUTE(A1,CHAR(160),"")
or, to convert it in one step to a number:
=--SUBSTITUTE(A1,CHAR(160),"")
Note If the character code is >255, use UNICHAR instead of CHAR in the SUBSTITUTE function.
Without an example, I use value() to convert what excel takes as text like so:
=value(left(“10kg”,2))
Or the following also works:
=left(“10kg”,2)*1
Note those double quotes should be the straight ones - sorry smartphone is not always smart...
And if leading or trailing spaces are an issue, then trim() is one solution.

Hyperlink formula not working despite displaying correct address

I am using the formula:
=HYPERLINK(CELL("address",INDIRECT("'"&C38&"'!A1")))
Where C38 contains
0999-0165
and I have a sheet called 0999-0165. There are no leading or trailing characters, and since the name in C38 is generated by the sheetname there is no error between 0 and O.
The sheet has also been saved to my desktop as dtest.xlsx
When I click on the formula, I get the following error:
MS Help indicates that I should be going down the right path here:
Where did I go wrong
What do I need to do to adjust this formula to make it work so that I can simply copy the formula up or down to create other links for other reference sheetnames in column C?
I also did the work around from this question but it did not seem to help.
Muddying the water
When I use a direct cell reference and drop the indirect part for testing purposes to make it look the same as the MS Help recommendation, I wind up with the same error:
=HYPERLINK(CELL("address",'0999-0165'!A1))
And BTW, the above formula winds up displaying the same as the Indirect one. Complete with adding the $
Here's a long workaround to this, if you don't want to hard-code the workbook name. Get the entire filename with CELL("filename",A1) and then extract just the workbook name and the enclosing brackets using MID and FIND.
=HYPERLINK(MID(CELL("filename",A1),FIND("[",CELL("filename",A1)),FIND("]", CELL("filename",A1))-FIND("[",CELL("filename",A1))+1)&"'"&C38&"'!$A$1")
Or slightly more simple:
=HYPERLINK(SUBSTITUTE(SUBSTITUTE(CELL("address",INDIRECT("'"&C38&"'!A1")),"'[","["),"]","]'"))

Text instead of integer in Excel formula

I just received an Excel file from a colleague and I'm baffled by one of the formulas.
It's a Vlookup function where the column index number is equal to DTCN.
I tried looking up this formula but can't find it anywhere. Here it is:
=VLOOKUP($A15;KPI!$A$4:$AN$133;DTCN;FALSE)
What really matters:
=VLOOKUP(lookup value; table array; DTCN; range lookup)
I work in Excel 2010 and the formula works.
My question: What does DTCN do? How does it work? Can you only use in certain circumstances? ...
Thanks!
Take a look in :
Formula tab
Name Manager
you'll most probably find it there!

What Excel formula returns the sheet name?

I have searched the excel function documentation and general MSDN search but have been unable to find a way to return the sheet name without VBA.
Is there a way to get the sheet name in an excel formula without needing to resort to VBA?
Not very good with excel, but I found these here
=MID(CELL("filename",A1),FIND("]",CELL("filename",A1))+1,256)
and A1 can be any non-error cell in the sheet.
For the full path and name of the sheet, use
=CELL("filename",A1)
Here's a reasonably short one that has a couple added benefits:
Does a reverse lookup (most other answers go wrong direction) by using the often ignored REPT function.
A1 seems like a poor choice as there's a considerably higher chance it errors compared to... $FZZ$999999.
Don't forget to absolute. Copying and pasting some of the other examples could error due to referential changes.
The ? is intentional as that shouldn't be in the file path.
=SUBSTITUTE(RIGHT(SUBSTITUTE(CELL("Filename",$FZZ$999999),
"]",REPT("?", 999)), 999),"?","")
The below will isolate the sheet name:
=RIGHT(CELL("filename"),LEN(CELL("filename"))-FIND("]",CELL("filename")))
For recent versions of Excel, the formula syntax is:
=MID(CELL("filename";A1);FIND("]";CELL("filename";A1))+1;255)
None of the formulas given in other answers supports the case if there is character ] in filepath.
The formula below is more complex, but it can handle such cases properly:
=MID(CELL("filename",A1),FIND("]",CELL("filename",A1),FIND("?",SUBSTITUTE(CELL("filename",A1),"\","?",LEN(CELL("filename",A1))-LEN(SUBSTITUTE(CELL("filename",A1),"\","")))))+1,LEN(CELL("filename",A1)))
I had a module already open so I made a custom function:
Public Function Sheetname (ByRef acell as Range) as string
Sheetname = acell.Parent.Name
End Function
Had a square bracket ']' in the file name, so needed to modify the above formula as per the following to find the last occurrence of the square bracket.
Verified that this works for 0,1 or more square brackets in the file name / path.
=RIGHT(CELL("filename"),LEN(CELL("filename")) - FIND("]]]",SUBSTITUTE(CELL("filename"),"]","]]]",LEN(CELL("filename"))-LEN(SUBSTITUTE(CELL("filename"),"]","")))))
Replaces all square brackets using the substitute function, then compares the length of the result with the length of the file name to identify the number of square brackets in the file name.
Uses the number of occurrences of square brackets to substitute the last square bracket with 3 sequential square brackets ']]]'
Uses the Find function to identify the location of the 3 square brackets in the string
Subtracts the location of the 3 square brackets from the length of the full path
Uses the result to get the right most characters (being the sheet name)
Previous comment above about saving the workbook first is also a key, as you'll otherwise receive the #Value! result.
The below works for me and is simpler (to me at least) than other solutions, while still handling a square bracket in the file name:
=MID(CELL("filename", A1),6+SEARCH(".xlsx]",CELL("filename", A1)),32)
This assumes it is an "xlsx" file and that the filename will not contain ".xlsx]" in addition to the xlsx suffix, which in my case is an assumption that is safe enough to make.
If you wanted to handle both ".xlsx" and ".xls" file names, you could use:
=MID(SUBSTITUTE(CELL("filename", A1),".xls]",".xlsx]"),6+SEARCH(".xlsx]",SUBSTITUTE(CELL("filename", A1),".xls]",".xlsx]")),32)
I'm pretty sure you could have Googled this. I just did, and here is the very first thing that came up for me.
In Excel it is possible to use the CELL function/formula and the MID and FIND to return the name of an Excel Worksheet in a Workbook. The formula below shows us how;
=MID(CELL("filename",A1),FIND("]",CELL("filename",A1))+1,256)
Where A1 is any non error cell on the Worksheet. If you want the full path of the Excel Workbook, simply use;
=CELL("filename",A1)
The only catch is that you have to save the file for this to work!

VBA eats my zeros INSIDE a string?

So here is a problem that I have never come across before. I Import an ISIN (for example DE0002635307) from a cell, which is defined as a text. I need to use this to reference to a cell by that name. So:
sub ISINWriter
dim ISIN as String
ISIN = ThisWorkbook.Sheets(i).Cells(j, 4).Value()
ThisWorkbook.Sheets(i+1).Cells(f, 4).Formula = "=" & ISIN
End Sub
For most of the ISINs this works fine, except if there are 4 or more zeros in a row. If that happens - for example FR0000120073 - it writes "=FR120073" into the cell. It just eats the zeros INSIDE the string! Any ideas?
I use Excel 2010 and Windows 7.
Thanks a lot.
If you use the Name Manager to try to create a named range (or more accurately a named formula) called "FR0000120073" then you should find that you get an error. Something like (from Excel 2007 on my machine):
The name that you entered is not valid.
Reasons for this can include:
- The name does not begin with a letter or an underscore
- The name contains a space or other invalid characters
- The name conflicts with an Excel built-in name or the name of another object in the workbook
The clue is in the last part of the third reason. FR120073 is a valid cell address in these days of 16Kx1m cell worksheets.
The first reason above may be useful, though: _FR0000120073 is a valid name. Could you use that?
EDIT: Removing my last answer so this makes sense.
Basically your cell references are an AlphaNumeric value. Take A1 for example A is the column 1 is the row. This issue is occuring because 0001 is the same as 1. so a reference to cell A001 is going to be the same as cell A1.
It looks like Excel has some built in functionality to remove leading 0's from your references to cells.

Resources