+ Reply to Thread
Results 1 to 5 of 5

Decimal Degrees to Degree Minutes Seconds Conversion VBA Stripping Leading Zeros

  1. #1
    Registered User
    Join Date
    06-18-2012
    Location
    New Zealand
    MS-Off Ver
    Excel 2002
    Posts
    7

    Decimal Degrees to Degree Minutes Seconds Conversion VBA Stripping Leading Zeros

    I am using Excel to average angles derived from GPS measurements.

    Angles are imported into Excel with no spaces after the ° and ' symbols; ie 123°05'09".

    I am using VBAs obtained from the following link:

    http://support.microsoft.com/kb/213449

    to convert angles between decimal degrees and degree minutes seconds.

    These VBAs require a space after the ° and ' symbols; ie 123° 05' 09", which I create with the SUBSTITUTE function.

    Angles are then converted to decimal degrees averaged then converted back to degrees minutes seconds.

    Unfortunately the final step strips leading zeros before minutes and seconds that are single digit numbers; ie 123° 5' 9".

    I need to retain the leading zeros so i can import these values directly into another package.

    Does anyone have any suggestions?

    Thanks in advance.

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Decimal Degrees to Degree Minutes Seconds Conversion VBA Stripping Leading Zeros

    Hello JTHOM,

    Welcome to he Forum!

    This version of the macro will insure there is always 2 zeroes in each place holder when the value is less than 10.
    Please Login or Register  to view this content.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Registered User
    Join Date
    06-18-2012
    Location
    New Zealand
    MS-Off Ver
    Excel 2002
    Posts
    7

    Re: Decimal Degrees to Degree Minutes Seconds Conversion VBA Stripping Leading Zeros

    Leith,

    Thanks for your reply.

    The VBA you attached returned the following results:

    Input Result Actual
    213.1505556 213° 9' 0 213° 09' 02"
    240.0552778 240° 3' 0 240° 03' 19"
    160.2605556 160° 16' 0 160° 15' 38"

    I comment the seconds values are incorrectly rounded, the leading zeros for single digit minute values and the seconds symbols are dropped.

    Could you please advise me if this only apparant on my end.

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Decimal Degrees to Degree Minutes Seconds Conversion VBA Stripping Leading Zeros

    Hello JTHOM,

    You're correct. The code does round the seconds to zero. That appears to be bad editing on my part. Try this version. It appears to work correctly on my end.
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    06-18-2012
    Location
    New Zealand
    MS-Off Ver
    Excel 2002
    Posts
    7

    Re: Decimal Degrees to Degree Minutes Seconds Conversion VBA Stripping Leading Zeros

    Leith,

    Thanks alot works great.

    As the " symbol was still not apparent I added it at the very end of your VBA.

    The final product is attached below:

    Please Login or Register  to view this content.
    Thanks again.

    [SOLVED]

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1