VB:
Function DMS2Deg(ByVal sInp As String) As Double
Dim sSgn As Long
Dim i As Long
Dim avs As Variant
sSgn = IIf(Left(WorksheetFunction.Trim(sInp), 1) = "-", -1, 1)
For i = 1 To Len(sInp)
If InStr(" .0123456789", Mid(sInp, i, 1)) = 0 Then Mid(sInp, i) = " "
Next i
avs = Split(WorksheetFunction.Trim(sInp), " ")
DMS2Deg = sSgn * (avs(0) + avs(1) / 60# + avs(2) / 3600#)
End Function
Adding a Macro to a Code Module
1. Copy the code from the post
2. Press Alt+F11 to open the Visual Basic Editor (VBE)
3. From the menu bar in the VBE window, do Insert > Module
4. Paste the code in the window that opens
5. Press Alt+Q to close the VBE and return to Excel
Then with -43° 16'0.40" in A1,
=DMS2Deg(A1) returns -43.2667777777778
Bookmarks