XL: Custom Function to Express Degree as Fractions of Degrees

Last reviewed: February 3, 1998
Article ID: Q121944
The information in this article applies to:
  • Microsoft Excel for Windows, versions 5.0, 5.0c
  • Microsoft Excel for the Macintosh, versions 5.0, 5.0a
  • Microsoft Excel for Windows NT, version 5.0
  • Microsoft Excel for Windows 95, versions 7.0, 7.0a
  • Microsoft Excel 97 for Windows
  • Microsoft Excel 98 Macintosh Edition

SUMMARY

Fractions of a degree are commonly expressed in units called minutes and seconds. One degree is equivalent to 60 minutes, and similarly, one minute equals 60 seconds. These units are most commonly used for expressing a navigational point such as a point on a nautical chart.

Although Microsoft Excel lacks a built-in number format to express these terms, this article contains a sample custom function you can use to convert a degree value (stored in decimal format, or base 10) to degrees, minutes, and seconds (stored in text format).

MORE INFORMATION

Microsoft provides programming examples for illustration only, without warranty either expressed or implied, including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose. This article assumes that you are familiar with the programming language being demonstrated and the tools used to create and 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 needs. If you have limited programming experience, you may want to contact the Microsoft fee-based consulting line at (800) 936-5200. For more information about the support options available from Microsoft, please see the following page on the World Wide Web:

   http://www.microsoft.com/support/supportnet/refguide/default.asp

For a similar example using the Excel 4.0 macro language, please see the following article in the Microsoft Knowledge Base:

   ARTICLE-ID: Q73023
   TITLE     : Converting a Decimal Degree Value to Degrees, Minutes,
               Seconds

The following Microsoft Visual Basic for Applications custom function accepts an angle formatted as a decimal value and convert it to a text value displayed in degrees, minutes, and seconds.

Sample Visual Basic Procedure

   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:

   =Convert_Degree(10.46)

This formula will return 10~ 27' 36" (that is, 10 degrees, 27 minutes, 36 seconds).

REFERENCES

For additional information about getting help with Visual Basic for Applications, please see the following article in the Microsoft Knowledge Base:

   ARTICLE-ID: Q163435
   TITLE     : VBA: Programming Resources for Visual Basic for
               Applications


Additional query words: 5.00 5.00a 5.00c 7.00 7.00a 97 98 XL98 XL97 XL7 XL5
Keywords : kbcode kbprg PgmHowto PgmOthr
Version : WINDOWS:5.0,5.0c,7.0,97; MACINTOSH:5.0,5.0a,98
Platform : MACINTOSH WINDOWS
Issue type : kbhowto


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: February 3, 1998
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.