I have a excel file with a zip codes and I need get the first 2 numbers
=LEFT(G2;2);
for this postal codes like 11008 it works, I get 11, but if a postal code has as value 01008 this doesn't works because the unformatted (Real Value) value is 1008
Any ideas?
You could turn the zip code first into text using TEXT:
=LEFT(TEXT(G2;"00000");2)
1008 becomes 01008 first, and then you get 01 from the LEFT function.
Your ZIP code column should really be formatted as Text. Even though the ZIP code happens to be represented with numerals, it's not really a number per se.
You don't do math with it;
it could just as easily be represented with letters (and is in some countries);
leading zeros are important.
Same thing with, say, phone numbers.
Here's some relevant questions:
Is it a good idea to use an integer column for storing US ZIP codes in a database?
Phone Number Columns in a Database
Related
I'm trying to write an Excel macro using VBA that will return only the first 5 numbers in a cell when the length of that cell exceeds 20. The field normally returns 15-digit alphanumeric results (which I need to leave alone) but in certain exceptions will return a 5-digit number with a multitude of zeroes following it (1234500000000000000000000...) which Excel converts into scientific notation (1.2345E+160). I am able to convert the cells to numbers instead of scientific notation and view the whole number.
I've tried to use code such as =IF(LEN(A1)>20,LEFT(A1,5),A1) and it just returns 1.2345E+160. Even though the whole number is displaying, Excel still thinks the cell length is 11 and won't display the first 5 digits.
I've also tried lines such as =IF(A1="E",LEFT(A1,6),A1) thinking it would detect the E, return 1.2345, and I could just remove the decimal points, but that didn't work either (it just returns the original 1.2345E+160).
I got the same results whether the cell was formatted as number or text. Is there a way around this?
Thank you for your time!
You are trying to use string manipulation on a number. Instead use math:
=A1/1E+160
If you do actually want to treat this thing as text, understand that the underlying value being stored is your 12345000000000000... and there is no decimal point in that thing. So you'll have to convert to text and add the decimal:
=LEFT(TEXT(A1,"0"), 1) & "." & MID(TEXT(A1,"0"), 2, 4)
But that's pretty ugly. I would just stick with math.
I have a list of addresses from which I need to extract the last sequence of numbers (zip code). I'm looking for a general expression from which I can extract the zip codes from addresses from all over the world. I would have to tweak the expression in order for it to work for each country, or for a group of countries, I assume.
I'm trying to write a formula in excel that can recognise the last digit in a string, and from that, extract the numbers immediately before that last digit and stoping whenever it reaches a non-integer. Below I have an example of an address and the formula I've come up with (in E26), but I'm looking for something more compact:
National Institute of Pharmaceutical Education and Research (NIPER), Phase X, Sector 67, SAS Nagar, Punjab, 160062, India.
=MID(E26, MAX(IF(ISNUMBER(VALUE(MID(E26,ROW(INDIRECT("1:" & LEN(E26))),1))),ROW(INDIRECT("1:" & LEN(E26))))+1)-6, 6)
The first part of recognizing the last digit is working fine, the problem is to recognize the beggining of the sequence, at least in cases where there's also street numbers within the string (such as in this case). This is why I'm subtacting -6 to the position where the last digit was found, since I know the lenght of the zip code in this particular country. However, it may not be the case for all countries.
Plus there are cases, where there's a space between the sequence such as: 160 062. Also, they won't always have delimeters that I could use to extract the zip codes, hence, the reason why a need an algorithm for this.
I was wondering if there's a nitter way to do this? I would be open for VBA. Thanks for your help!
Best regards,
Antonio
For a piece of coursework I have to complete a register of student grades. I am trying to calculate their overall grades by converting their grades from each of the four units into numbers (which I have done using the VLOOKUP function), but I need to then convert the result of the average back into a letter. I have used VLOOKUP and also a long nested IF statement to try and accomplish this, but no matter what I can never get a valid result. This is what I have so far (this is just a link to my image as I am unable to post one).
I have converted the Target grade into a number using the formula:
=VLOOKUP(D3,'Grade Values'!A$2:B$11,2,FALSE)
Then added up the total of the different grades from the four units using this formula:
=SUM(VLOOKUP(F3,'Grade Values'!A$1:B$11,2,FALSE)+
VLOOKUP(Dashboard!G3,'Grade Values'!A$1:B$11,2,FALSE)+
VLOOKUP(Dashboard!H3,'Grade Values'!A$1:B$11,2,FALSE)+
VLOOKUP(Dashboard!I3,'Grade Values'!A$1:B$11,2,FALSE))
And then averaged it out with this: =J3/4
The problem I am facing at the moment is that when converting this number back to a letter using the same table as in the second screenshot I get an N/A result when I use this formula: =VLOOKUP(K3,Dashboard!A1:B10,1,FALSE)
I can't seem to figure out what's going wrong with the formula at the end. If anyone can please help me figure this out I will appreciate it a lot. Thank you :)
Edit: I apologise for the irrelevant tags, as far as I was aware formulas in Excel were written in JavaScript.
Personally, I would convert the letter grade to ASCII character using the function:
CODE(A1)
use the ASCII Reference Chart for the integer value of each Upper Case character. Note: A=65, B=66, etc... Perform your calculations, then you can use the function:
CHAR(A2)
to convert the number back into a character.
Example:
A1="A"
A2="B"
A3="C"
B1="=CHAR(AVERAGE(CODE(A1),CODE(A2),CODE(A3)))"
just copy the column A in the sheet dashboard and paste it in column C in the sheet dashboard... so you have
A B C
A* 7 A*
A 7 A
B 6 B
....
the formula you have to use is
=VLOOKUP(K3,Dashboard!$B$1:$C$10,2,FALSE)
remember that this time u need to match a number... not a letter
I'm building a VBA program on Excel 2007 inputing long string of numbers (UPC). Now, the program usually works fine, but sometimes the number string seems to be converted to scientific notation and I want to avoid this, since I then VLook them up.
So, I'd like to treat a textbox input as an exact string. No scientific notation, no number interpretation.
On a related side, this one really gets weird. I have two exact UPC : both yield the same value (as far as I or any text editor can tell), yet one of the value gives a successful Vlookup, the other does not.
Anybody has suggestions on this one? Thanks for your time.
Long strings that look like numbers can be a pain in Excel. If you're not doing any math on the "number", it should really be treated as text. As you've discovered, when you want to force Excel to treat something as a string, precede it with an apostrophe.
There are a couple of common problems with VLOOKUP. The one you found, extra whitespace, can be avoided by using a formula such as
=VLOOKUP(TRIM(A1),B1:C:100,2,FALSE)
The TRIM function will remove those extraneous spaces. The other common problem with VLOOKUP is that one argument is a string and the other is a number. I run into this one a lot with imported data. You can use the TEXT function to do the VLOOKUP without having to change the raw data
=VLOOKUP(TEXT(A1,"00000"),B1:C100,2,FALSE)
will convert A1 to a five digit string before it tries to look it up in column B. And, of course, if your data is a real mess, you may need
=VLOOKUP(TEXT(TRIM(A1),"00000"),B1:C100,2,FALSE)
There are many, many questions and quality answers on SO regarding how to prevent leading zeroes from getting stripped when importing to or exporting from Excel. However, I already have a spreadsheet that has values in it that were truncated as numbers when, in fact, they should have been handled as strings. I need to clean up the data and add the leading zeros back in.
There is a field that should be four characters with lead zeros padding out the string to four characters. However:
"23" should be "0023",
"245" should be "0245", and
"3829" should remain "3829"
Question: Is there an Excel formula to pad these 0's back onto these values so that they are all four characters?
Note: this is similar to the age old Zip Code problem where New England-area zip codes get their leading zero dropped and you have to add them back in.
=TEXT(A1,"0000")
However the TEXT function is able to do other fancy stuff like date formating, aswell.
The more efficient (less obtrusive) way of doing this is through custom formatting.
Highlight the column/array you want to style.
Click ctrl + 1 or Format -> Format Cells.
In the Number tab, choose Custom.
Set the Custom formatting to 000#. (zero zero zero #)
Note that this does not actually change the value of the cell. It only displays the leading zeroes in the worksheet.
I hit this page trying to pad hexadecimal values when I realized that DEC2HEX() provides that very feature for free.
You just need to add a second parameter. For example, tying to turn 12 into 0C
DEC2HEX(12,2) => 0C
DEC2HEX(12,4) => 000C
... and so on
I know this was answered a while ago but just chiming with a simple solution here that I am surprised wasn't mentioned.
=RIGHT("0000" & A1, 4)
Whenever I need to pad I use something like the above. Personally I find it the simplest solution and easier to read.
I am not sure if this is new in Excel 2013, but if you right-click on the column and say "Special" there is actually a pre-defined option for ZIP Code and ZIP Code + 4. Magic.
If you use custom formatting and need to concatenate those values elsewhere, you can copy them and Paste Special --> Values elsewhere in the sheet (or on a different sheet), then concatenate those values.
Even this will work nicely
REPT(0,2-LEN(F2)&F2
where 2 is total number of digits, for 0 ~ 9 -> it will display 00 to 09 rest nothing will be added.
Assuming that the number you want to pad is in cell A1, and the "padding number of zeros" is 4 ,
e.g.
"23" should be "0023",
"245" should be "0245", and
"3829" should remain "3829"
then
=TEXT(A1,REPT("0",4))