2011-11-16 253 views
0

我有大約200的緯度和在我的excel表不同的地方,其是于格式Excel公式計算

度,分鐘和秒 - 對於例如200個經度:36°34" 44'

這個值存儲在一個單元格中

我想用公式,度數+分鐘/ 60 +秒/ 3600將這個值轉換爲小數。請告訴我如何在每個單元格中應用相同的值。所有的度數,分和秒都在同一個單元格中。提前致謝!

回答

2

下面是示例VBA函數,你可能可以使用:

Function Convert_Decimal(Degree_Deg As String) As Double 
    Dim degrees As Double 
    Dim minutes As Double 
    Dim seconds As Double 
    ' Set degree to value before "°" of Argument Passed. 
    degrees = Val(Left(Degree_Deg, InStr(1, Degree_Deg, "°") - 1)) 
    ' Set minutes to the value between the "°" and the "'" 
    ' of the text string for the variable Degree_Deg divided by 
    ' 60. The Val function converts the text string to a number. 
    minutes = Val(Mid(Degree_Deg, InStr(1, Degree_Deg, "°") + 2, _ 
      InStr(1, Degree_Deg, "'") - InStr(1, Degree_Deg, _ 
      "°") - 2))/60 
    ' Set seconds to the number to the right of "'" that is 
    ' converted to a value and then divided by 3600. 
    seconds = Val(Mid(Degree_Deg, InStr(1, Degree_Deg, "'") + _ 
      2, Len(Degree_Deg) - InStr(1, Degree_Deg, "'") - 2)) _ 
      /3600 
    Convert_Decimal = degrees + minutes + seconds 
End Function 

要使用,只需鍵入=Convert_Decimal("36°34"44'"),您將得到結果36.58。

另外,如果你有興趣,你可以看看the other approach利用時間格式功能。

希望這些會有所幫助。

MSDN上更多的細節:

http://support.microsoft.com/kb/73023

http://support.microsoft.com/kb/213449

http://www.cpearson.com/excel/LatLong.aspx

+0

非常感謝...!它真的幫了大忙! :d – Chandeep

0

如果你的字符串作爲零填充(如06°04"04'),然後使用

=VALUE(LEFT(A1,2))+VALUE(MID(A1,4,2))/60+VALUE(MID(A1,7,2))/3600 

如果不是,或不確定(如6°4"4'),然後使用

=VALUE(LEFT(A1,FIND("°",A1)-1)) + 
VALUE(MID(A1,FIND("°",A1)+1,FIND("""",A1)-FIND("°",A1)-1))/60 + 
VALUE(MID(A1,FIND("""",A1)+1,FIND("'",A1)-FIND("""",A1)-1))/3600