首页 > 解决方案 > 将 Lat/Lon 从十进制、分钟、秒 (00000000) 转换为整数坐标 (00.000000)

问题描述

我有 182 组十进制分秒 (DMS) 坐标需要转换为整数坐标。我有一个从某种格式 ( 00° 00' 00.00") 转换的代码,但无法将我的数据从00000000. 问题似乎是我不能使用自定义格式的“。当我手动将 DMS 符号添加到数据中时,我的代码可以工作。

我试图将单元格格式化为看起来像00° 00' 00.00",但它返回错误

“Excel 无法使用您键入的数字格式。”

我知道 " 是问题所在,因为我能够输入不包括该符号但包含其他两个符号的格式。

Function Convert_Decimal(Degree_Deg As String) As Double
   ' Declare the variables to be double precision floating-point.
   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

此代码按预期工作,但我无法格式化我的数据以使用此代码。

我没有编写该代码,并且我几乎没有编写代码的经验,我可以将此代码更改为不需要 " 符号或将所需的符号更改为我可以格式化为我的数据的符号吗?

有没有更简单的方法将我的数据从 DMS 转换为整数坐标?

标签: excel

解决方案


推荐阅读