2011-11-16 206 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