You are currently offline, waiting for your internet to reconnect

XL98: Function to Convert Degree to/from Fractions of Degrees

This article was previously published under Q192367
Retired KB Content Disclaimer
This article was written about products for which Microsoft no longer offers support. Therefore, this article is offered "as is" and will no longer be updated.
Fractions of a degree are commonly expressed in units called minutes andseconds. One degree is equivalent to 60 minutes, and similarly, one minuteequals 60 seconds. These units are most commonly used for expressing anavigational point such as a point on a nautical chart.

Although Microsoft Excel 98 Macintosh Edition lacks a built-in numberformat to express these terms, this article contains a sample customfunction you can use to convert a degree value (stored in decimal format,or base 10) to degrees, minutes, and seconds (stored in text format). Also,this article contains a user-defined function that converts degrees,minutes, and seconds (stored in text format) to a degree value (stored indecimal format).
Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements.

Converting Decimal Degrees to Degrees/Minutes/Seconds

The following Microsoft Visual Basic for Applications custom functionaccepts an angle formatted as a decimal value and convert it to a textvalue 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 followingexample:
This formula will return 10~ 27' 36" (that is, 10 degrees, 27 minutes, 36seconds).

Converting Degrees/Minutes/Seconds to Decimal Degrees

The following Microsoft Visual Basic for Applications custom functionaccepts a text string of degrees, minutes and seconds formatted in theexact same format that the Convert_Degree function returns (for example,10~ 27' 36") and converts it to an angle formatted as a decimal value. Thisis exactly the reverse of the Convert_Degree custom function.

WARNING: This custom function fails if the Degree_Deg argument does notfollow the format of the following:
  <degrees>~ <minutes>' <seconds>"				
as stated earlier.
Function Convert_Decimal(Degree_Deg As String) As Double   ' Declare the variables to be double precision floating-point.   Dim degrees As Double   Dim minutes As Double   Dim seconds As Double   ' Set degree to value before "~" of Argument Passed.   degrees = Val(Left(Degree_Deg, InStr(1, Degree_Deg, "~") - 1))   ' Set minutes to the value between the "~" and the "'"   ' of the text string for the variable Degree_Deg divided by   ' 60. The Val function converts the text string to a number.   minutes = Val(Mid(Degree_Deg, InStr(1, Degree_Deg, "~") + 2, _             InStr(1, Degree_Deg, "'") - InStr(1, Degree_Deg, _             "~") - 2)) / 60    ' Set seconds to the number to the right of "'" that is    ' converted to a value and then divided by 3600.    seconds = Val(Mid(Degree_Deg, InStr(1, Degree_Deg, "'") + _            2, Len(Degree_Deg) - InStr(1, Degree_Deg, "'") - 2)) _            / 3600   Convert_Decimal = degrees + minutes + secondsEnd Function				
To use this function, create a conversion formula, as in the followingexample:
   =Convert_Degree("10~ 27' 36""")				
This formula will return 10.46 (that is, 10.46 degrees).

NOTE: You are required to type three quotation marks (""") at the end ofargument of this formula to balance the quotation mark for the secondsand the quotation mark for the text string.

Article ID: 192367 - Last Review: 06/17/2005 23:54:05 - Revision: 2.0

  • Microsoft Excel 98 for Macintosh
  • kbdtacode kbhowto KB192367