Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 25
Default Formatting for Degrees Minutes and Seconds

Hi there folks.

I am trying to format Degrees expressed as a decimal amount as
Degrees Minutes Seconds

The [h]:mm:ss format given in the custom section of the "Format Cells"
dialogue box does only a tolerable job and I need to divide the Decimal
Degrees by 24 first, in order to achieve that.

So... in order to achieve my goal I have decided to write my own UDF.
Although this does not leave me with an underlying numeric value, (and
that is not a real bad thing) I cannot discover a way to insert a °
(°)character into the output string.

The function code is as follows:

Function formDMS(DecDeg)
If DecDeg < 0 Then DecDeg = DecDeg * (-1)
d = Int(DecDeg)
m = (DecDeg - d) * 60
im = Int(m)
s = Round((m - Int(m)) * 60, 0)
formDMS = d & ":" & im & "'" & s & """"
End Function
---------------^------------------------
it is the character above the "^" that needs to be modified.

any ideas... would be appreciated

Regards
Geoff

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 162
Default Formatting for Degrees Minutes and Seconds

formDMS = d & Chr(&HB0) & " " & im & "' " & s & """"

You can get the unicode hex number (B0 in this case) for a symbol from
the Insert Symbol dialog box. Take the number and prefix it with &H
to put it in VB Hex form. then convert the number to a character with
the Chr() function.

Or, just that little degree symbol that you just inserted in your post
above, copy it, and paste it into your VBA editor. Or just copy the
following line:

formDMS = d & "° " & im & "' " & s & """"

I just tried it. It works too. :-)

----
Nick Hebb
BreezeTree Software
http://www.breezetree.com

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 25
Default Formatting for Degrees Minutes and Seconds

Sure does Nick.... Thanks a heap.

----
Geoff

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Converting Decimal Degrees to Degrees/Minutes/Seconds Larry_Klotz Excel Worksheet Functions 1 November 2nd 09 07:22 PM
How do you convert decimal degrees to degrees minutes seconds David Excel Discussion (Misc queries) 2 September 21st 06 09:38 PM
how can i convert degrees/minutes/seconds to decimal degrees? Chrissy Excel Discussion (Misc queries) 2 April 28th 06 12:14 PM
calculate from degrees to degrees/minutes/seconds on excel? C. Hollinger Excel Worksheet Functions 1 March 14th 06 08:57 PM
converting from digital degrees to degrees minutes seconds Patricio Boric Excel Worksheet Functions 1 November 28th 04 07:43 PM


All times are GMT +1. The time now is 07:57 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"