Quote:
Originally Posted by OTPM
|
Hi
I would like to have this without doing the seconds separate, just as a decimal to the minutes
Converting Decimal Degrees to Degrees/Minutes/Seconds
The following Microsoft Visual Basic for Applications custom function accepts an angle formatted as a decimal value and converts it to a text value displayed in degrees, minutes, and seconds.
Function Convert_Degree(Decimal_Deg) As Variant
With Application
'Set degree to Integer of Argument Passed
Degrees = Int(Decimal_Deg)
'Set minutes to 60 times the number to the right
'of the decimal for the variable Decimal_Deg
Minutes = (Decimal_Deg - Degrees) * 60
'Set seconds to 60 times the number to the right of the
'decimal for the variable Minute
Seconds = Format(((Minutes - Int(Minutes)) * 60), "0")
'Returns the Result of degree conversion
'(for example, 10.46 = 10~ 27 ' 36")
Convert_Degree = " " & Degrees & "° " & Int(Minutes) & "' " _
& Seconds + Chr(34)
End With
End Function
To use this function, create a conversion formula, as in the following example:
Start Excel and press ALT+F11 to start the Visual Basic editor.
On the Insert menu, click Module.
Enter the sample code for the Convert_Degree custom function described above into the module sheet.
Press ALT+F11 to return to excel.
In cell A1 type 10.46.
In cell A2 type the following formula:
=Convert_Degree(A1)