excel公式计算
我的excel表格中有大约200个纬度和200个不同的地方,
度,分和秒 – 例如:36°34“44”
该值存储在一个单元格中。
我想要使用公式,度+分钟/ 60 +秒/ 3600将此值转换为小数。 请告诉我如何在每个细胞中应用相同的方法。 问题是所有的度,分和秒都在同一个单元格中。 提前致谢!
下面是您可能可以使用的示例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。
另外,如果你有兴趣,你可以看看利用时间格式函数的另一种方法 。
希望这些会有所帮助。
有关MSDN的更多详细信息:
http://support.microsoft.com/kb/73023
如果你的string为零填充(如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