Skip to main content
 

How to convert decimal degrees to degrees minutes seconds in Excel?

Author: Sun Last Modified: 2024-08-07

Sometimes, you may have a list of data shown as decimal degrees in a worksheet, and now you need to convert the decimal degrees to degrees, minutes and seconds formatting as shown as following screenshots, how can you get the conversation quickly in Excel?

decimal degrees data arrow degrees minutes seconds data

Convert decimal degrees to degrees, minutes, seconds with VBA

Convert degrees, minutes, seconds to decimal degrees with VBA


arrow blue right bubble Convert decimal degrees to degrees, minutes, seconds with VBA

Please follow the steps below to convert decimal degrees to degrees, minutes, and seconds with VBA code.

1. Hold ALT button and press F11 on the keyboard to open a Microsoft Visual Basic for Application window.

2. Click Insert > Module, and copy the VBA into the module.

VBA: Convert decimal degree to degree, minutes and seconds

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. Click Run button or press F5 to run the VBA.

4. A dialog displayed on the screen, and you can select the cells you want to the convert. See screenshot:

vba code to select the data to convert

5. Click OK, then the selected data is converted to degree, minutes and seconds. See screenshot:

original data arrow converting result

Tip: Using the above VBA code will lost your original data, so you’d better copy the data before running the code.



arrow blue right bubble Convert degrees, minutes, seconds to decimal degrees with VBA

Sometimes, you may want to convert the data in degrees/minutes/seconds formatting to decimal degrees, the following VBA code can help you quickly get it done.

1. Hold ALT button and press F11 on the keyboard to open a Microsoft Visual Basic for Application window.

2. Click Insert > Module, and copy the VBA into the module.

VBA: Convert degree, minutes and seconds to decimal degree

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. Save the code and close the window, select a blank cell, for instance, the Cell A1, enter this formula =ConvertDecimal("10° 27' 36""") ("10° 27' 36""" stands the degree you want to convert to decimal degree, you can change it as you need), then click Enter button. See screenshots:

enter the formula arrow result of converting degrees, minutes, seconds to decimal degrees

Relative articles