excel if statment problem. Please HELP!!?

2012-06-22 10:48 pm
Ok. So I have a column of longitude coordinate point on the excel.

It is like 5.7 W, 77.5E, 70.2E ..........

Here is what I want it to be,
5.7 W => -5.7
77.5E => 77.5
70.2E => 70.2

If it is E, the number should be positive; if it is W, the number should be negative.

Should I use if statement to do that? I got a thousand of data points so I really need a function statment to get the answer. Please help!!!!

Thanks

回答 (3)

2012-06-22 11:53 pm
✔ 最佳答案
here is a formula you can try

=IF(RIGHT(A1,1)="E", VALUE(SUBSTITUTE(UPPER(A1), "E","")),VALUE(SUBSTITUTE(UPPER(A1), "W",""))*-1)


hope that helps
2012-06-23 8:17 am
B1 =IF(ISBLANK(A1),"", IF(RIGHT(A1,1)="W", LEFT(A1,LEN(A1)-1)*-1, LEFT(a1.LEN(A1),1)*1))
2012-06-23 6:35 am
You are not clear in what you want. We don't know what "=>" means. Is there some valid reason you expect that to communicate useful information?
"5.7 W" is text, I assume. You didn't specify whether it is conditional formatting or the actual cell value.
I also will assume that the contents of each cell contain either a W or a E but not w, e, NE, SW, NNE, ENE, etc.
If what you wrote is strictly correct then it is easy. Otherwise, you can do it with some difficulty with an =IF() statement.
If the last character is always either a W or a E then the Right() function will give you that character. But if you have " xxx E " or "xxx e" then your task gets more complex.
So =Right(A1,1) is "W" if cell A1 contains "5.7 W"
So
=if(right(a1,1)="W",-1,
if(right(a1,1)="E",1,"* error *"))
will populate the cell that the formula is in with a -1 or +1 (or an error). You can simplify this by eliminating part of it to =if(right(a1,1)="W",-1,1) ...if you are absolutely sure that all of the cells always have a W or E in the last position.
To abstract the number is also easy if the position of the letter is fixed, as assumed above.
Here it is (take a deep breath)
=value(left(a1,len(a1)-1))
you can just multiply the two formulas together or combine them
=value((left(a1,len(a1)-1))*if(right(a1,1)="W",-1,if(right(a1,1)="E",1,"* error *"))
--------------------------
If the rightmost character is not always a W or E then it is much more difficult
You can change lower case e and w to E and W with =Upper()
And you can determine the existence in a cell of a character W or E at a variable position with the =find("W", a1) function but this (stupidly) returns an error if it doesn't find the desired string, so you need to include a conditional =if(iserror(find("W",A1)=true, -1, 1) {for the guaranteed case}
it again is easier if the column is guaranteed to have either W or E for sure.
to translate it: it looks for a W, if it does not find one anywhere in the cell, find returns a #error which means iserror() will return a true which means that the if() returns a -1 and since the only way it can't find a W is if there is an E in the cell, then we're good to go.
//edit - I believe I may have mixed up the signs on the if(iserror(...),1, -1) formula. You can check.
Yahoo truncated my formula. GDamn it!
WTF? it did it again!
and again *sigh*
I will break it up onto 2 lines
the formula that is still incomplete is just the other two multiplied, you get the idea.


收錄日期: 2021-04-25 13:45:33
原文連結 [永久失效]:
https://hk.answers.yahoo.com/question/index?qid=20120622144804AAX7FKP

檢視 Wayback Machine 備份