View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Michael Bednarek Michael Bednarek is offline
external usenet poster
 
Posts: 10
Default Small programming task in Excel VBA

On Sat, 12 Jul 2003 02:22:46 -0400, "John Johndon"
wrote in microsoft.public.excel.programming:

I am somewhat familiar with VB but never written anything for Excel at all,
so please be patient with me.

I need to run a macro or some VBA code to run on an Excel spreadsheet. The
spreadsheet consists of a couple of columns that contain latitudes and
longitudes. The latitudes (and longitudes) are in decimal format e.g
+26.1234 which needs to be converted into a degrees minutes and seconds
(DMS) format, the + or - sign signals either North or South latitude, so the
converted colum would look like 260724N which is 26 degrees, 07 minutes, and
24 seonds North.

[snip]
No VBA code necessary. A formula I came up with quickly is:
=(INT(ABS(A2))*10000+TEXT(INT(MOD(ABS(A2),1)*60)," 00")*100+INT(MOD(MOD(ABS(A2),1)*3600,60)))*SIGN(A2 )
will show 260724 when A2=26.1234 and -260724 when A2 = -26.1234

Formatting that with a hemisphere is left as an exercise for the
reader.

--
Michael Bednarek, IT Manager, Tactical Global Management
Waterfront Pl, Brisbane 4000, Australia. "POST NO BILLS"
http://mcmbednarek.tripod.com/