提示:其它语言是由 Google 机器翻译的。 你可以访问 English 版本。
登录
x
or
x
x
马上登记
x

or

如何在Excel中将十进制度转换为度分秒?

有时,您可能会在工作表中显示一个数据列表,显示为十进制度数,现在您需要将十进制度数转换为度数,分钟和秒数格式,如以下屏幕截图所示,如何在Excel中快速获取对话?

使用VBA将十进制度转换为度,分,秒

使用VBA将度数,分钟,秒转换为十进制度数

Office选项卡在Office中启用选项卡式编辑和浏览,使您的工作更轻松......
Kutools for Excel - 最佳办公生产力工具将解决您的大部分Excel问题
  • 重用任何东西: 将最常用或最复杂的公式,图表和其他任何内容添加到您的收藏夹中,并在将来快速重复使用它们。
  • 超过20文本功能: 从文本字符串中提取数字; 提取或删除部分文本; 将数字和货币转换为英语单词...
  • 合并工具:多个工作簿和表格合二为一; 合并多个单元格/行/列而不丢失数据; 合并重复行和总和...
  • 拆分工具:根据价值将数据拆分为多个表格; 一个工作簿到多个Excel,PDF或CSV文件; 一列到多列......
  • 粘贴跳过 隐藏/过滤行; 数和总和 按背景颜色; 创建邮件列表和 通过Cell的价值发送电子邮件...
  • 超级过滤器: 创建高级过滤方案并应用于任何工作表; 排序 按周,日,频率等; 筛选 通过大胆,公式,评论......
  • 超过300强大的功能; 适用于Office 2007-2019和365; 支持所有语言; 在公司轻松部署; 全功能60天免费试用。

箭头蓝色右泡 使用VBA将十进制度转换为度,分,秒


请按照以下步骤使用VBA代码将十进制度转换为度,分和秒。

1。 保持 ALT 按钮并按下 F11 在键盘上打开一个 Microsoft Visual Basic for Application 窗口。

2。 点击 插页 > 模块,并将VBA复制到模块中。

VBA:将十进制度转换为度,分和秒

Sub ConvertDegree()
'Update 20130815
Dim Rng As Range
Dim WorkRng As Range
On Error Resume Next
xTitleId = "KutoolsforExcel"
Set WorkRng = Application.Selection
Set WorkRng = Application.InputBox("Range", xTitleId, WorkRng.Address, Type:=8)
For Each Rng In WorkRng
    num1 = Rng.Value
    num2 = (num1 - Int(num1)) * 60
    num3 = Format((num2 - Int(num2)) * 60, "00")
    Rng.Value = Int(num1) & "°" & Int(num2) & "'" & Int(num3) & "''"
Next
End Sub

3。 点击 按钮或按下 F5 运行VBA。

4。 一个对话框显示在屏幕上,你可以选择你想要转换的单元格。 看截图:

5。 点击 OK,然后将选定的数据转换为度,分和秒。 看截图:

小技巧:使用上面的VBA代码会丢失原始数据,因此在运行代码之前最好复制数据。


箭头蓝色右泡 使用VBA将度数,分钟,秒转换为十进制度数

有时,您可能希望将度数/分/秒格式的数据转换为十进制度,下面的VBA代码可以帮助您快速完成。

1。 保持 ALT按钮并按下 F11 在键盘上打开一个Microsoft Visual Basic for Application窗口。

2。 点击 插页 > 模块,并将VBA复制到模块中。

VBA:将度,分和秒转换为十进制

Function ConvertDecimal(pInput As String) As Double
'Updateby20140227
Dim xDeg As Double
Dim xMin As Double
Dim xSec As Double
xDeg = Val(Left(pInput, InStr(1, pInput, "°") - 1))
xMin = Val(Mid(pInput, InStr(1, pInput, "°") + 2, _
             InStr(1, pInput, "'") - InStr(1, pInput, _
             "°") - 2)) / 60
xSec = Val(Mid(pInput, InStr(1, pInput, "'") + _
            2, Len(pInput) - InStr(1, pInput, "'") - 2)) _
            / 3600
ConvertDecimal = xDeg + xMin + xSec
End Function

3。 保存代码并关闭窗口,选择一个空白单元格,例如Cell A1,输入这个公式 = ConvertDecimal(“10°27'36”“”) (“10°27'36”“”代表您想要转换为十进制度的程度,您可以根据需要更改它),然后单击 输入 按钮。 查看截图:


相关文章

Say something here...
symbols left.
You are guest ( Sign Up? )
or post as a guest, but your post won't be published automatically.
Loading comment... The comment will be refreshed after 00:00.
  • To post as a guest, your comment is unpublished.
    ValdrichF · 4 months ago
    The code has a assumes there is a space after ° and '. Change the 2's to 1's in the code to solve it.
    Function ConvertDecimal(pInput As String) As Double
    'Updateby20140227
    Dim xDeg As Double
    Dim xMin As Double
    Dim xSec As Double
    xDeg = Val(Left(pInput, InStr(1, pInput, "°") - 1))
    xMin = Val(Mid(pInput, InStr(1, pInput, "°") + 1, _
    InStr(1, pInput, "'") - InStr(1, pInput, _
    "°") - 1)) / 60
    xSec = Val(Mid(pInput, InStr(1, pInput, "'") + _
    1, Len(pInput) - InStr(1, pInput, "'") - 1)) _
    / 3600
    ConvertDecimal = xDeg + xMin + xSec
    End Function
  • To post as a guest, your comment is unpublished.
    Sandeep · 1 years ago
    Works like a champ! Thanks for sharing!!!
  • To post as a guest, your comment is unpublished.
    ahans · 2 years ago
    please
    i want you help and write a computer program on paper to convert decimal of degree to degree minute and second.
    317.5986740026
    from ahans.
    • To post as a guest, your comment is unpublished.
      Amjid afridi · 1 years ago
      step 1, Multiply numbers after decimal with 60 (0.5986740026*60)minutes=35.92044015 mean 35 mints
      spet 2, multiply the decimal after minute ie 0.9204401*60=55.2264
      so 317 degree 35 minuts 55 sec
  • To post as a guest, your comment is unpublished.
    Corny · 2 years ago
    Not sure whats wrong with the code in the post from Ernie, but this is what I use to convert decimal degrees to DMS degrees in the spread sheet without using VB. The reference to the cell E33 is the cell containing the decimal degrees value.

    =CONCAT(FIXED(INT(B32), 0) , "°", FIXED(((B32 - INT(B32)) * 60), 0), "'", FIXED(((B32 - INT(B32) - INT(B32 - INT(B32))) * 3600), 0 ,TRUE), """)

    Good luck.
    • To post as a guest, your comment is unpublished.
      RAMON GOMEZ · 1 years ago
      HI CORNY, NOT WORK FOR ME, EXCEL DO NOT ACCEPT THE FUNCTION..... WHATS WRONG? CAN YOU HELP ME?
  • To post as a guest, your comment is unpublished.
    Ernie · 2 years ago
    Hello,
    I used the scrip to convert decimal to DMS however the code is wrong somewhere as it turned out 37.856908,-120.912469 to 37D 51M 25S, -121D 5M 15S
    This is way off....

    Anyone have a fix for this?
  • To post as a guest, your comment is unpublished.
    Ryan Smith · 2 years ago
    works great but how would i adapt the code to get more numbers for seconds?
  • To post as a guest, your comment is unpublished.
    Gregory · 3 years ago
    I want to plot the positions on a map and we not worry about N, S, E or W. I'm sure these could be added in with "if" statements.
    I have just used a very simple line of functions within the Excel spreadsheet.
    I want to go from Degrees (Decimal) to Degrees, Seconds (Decimal) Changing the negative values to positives as I know which hemispheres I am in. For me, cell E4 contained the target Lat or Long (Decimal).
    This is a bit easier than putting in some VBA code and can be enlarged to do DD,MM,SS

    =CONCATENATE(TRUNC(ABS(E4)),"°",FIXED((ABS(E4)-TRUNC(ABS(E4)))*60,2),"'")
  • To post as a guest, your comment is unpublished.
    Mou · 3 years ago
    Found this code very helpful. Great stuff!
  • To post as a guest, your comment is unpublished.
    Mort Wakeland · 3 years ago
    The most important thing to realize is that you cannot simply use superscript and small letter o for the degree symbol - this may be obvious to some, but not to me. I tried the superscript letter o and it did not work, I deleted the superscript letter o, and used Alt 0176 for the actual degree symbol and it worked!! I am confused as to why after the seconds there are extra sets of double quotes?
    36""") whereas in the subsequent comment if one simply uses =ConvertDecimal(A1) only a single set of quotes are used for seconds. Odd we can use single and double quotes and the thing works for minutes and seconds but superscript letter o does not?
    To check 27/60 = .45 smf 36/3600 = .01 add the two = .46 and add that to the degrees = 10.46 degrees. Hope this helps others? Mort
  • To post as a guest, your comment is unpublished.
    Levi · 5 years ago
    Really helpful.
    Thank you.
  • To post as a guest, your comment is unpublished.
    Rajansinh Zala · 5 years ago
    there is some error in code i tried to convert 26°10'55.416" using this code which results as 26.00139 which should be 26.18206 (Calculated & Verified.. please let me know if anyone knows the reason.
    • To post as a guest, your comment is unpublished.
      Gunnar · 5 years ago
      [quote name="Rajansinh Zala"]there is some error in code i tried to convert 26°10'55.416" using this code which results as 26.00139 which should be 26.18206 (Calculated & Verified.. please let me know if anyone knows the reason.[/quote]

      It seems the code expects a space after the ° and ' symbols.
      26° 10' 55.416" gives the correct answer.
      You can enter your input in a cell (eg A1) and get the result in another cell by using the formula =ConvertDecimal(A1). This is convenient if you have a many numbers to be converted.