can i do this with excel

AnimeKnight

Golden Member
Jan 8, 2000
1,823
2
0
My friend at work spend a lot of time converting degrees to minutes and seconds.. I was wondering if excel have a function that can help her out


i.e.
45.947 degree ---> 45degree56'49"

thanks in advance
 

Haircut

Platinum Member
Apr 23, 2000
2,248
0
0
I'm not aware of a built-in Excel function that does that, but I was bored so I wrote you one that does.

You will need to go into the Excel VB editor (Tools -> Macro -> Visual Basic Editor) and create a new module (Insert -> Module)
Now paste the following code into the editor screen


Function ConvertDegrees(ByVal iDegrees As Double, ByVal Precision As Integer) As String

Dim degs As Integer
Dim mins As Integer
Dim secs As Double

degs = Int(iDegrees)
mins = Int(60 * (iDegrees - degs))
secs = Round(60 * ((60 * (iDegrees - degs)) - mins), Precision)

' Because of rounding errors we need this bit
If secs = 60 Then
secs = 0
mins = mins + 1
End If

ConvertDegrees = degs & Chr(176) & " " & mins & "' " & secs & """"

End Function



You can now call this function from within Excel in the following way.

=ConvertDegrees (A1,1)

where A1 is the cell you want to convert to degree, minutes and seconds format and the number after that is the number of decimal places you want the seconds displayed to.

Hope this helps :)