View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.misc
EricG EricG is offline
external usenet poster
 
Posts: 220
Default Converting Lat/Lon coordinates to Decimal

I made these assumptions:
1. Latitude can be -90 to 90 degrees
2. Longitude can be -180 to 180 degrees
3. Your data are in Column A, starting at Row 3

Put this formula in Column B:

=IF(LEFT(A3,1)="-",LEFT(A3,3),LEFT(A3,2))+IF(LEFT(A3,1)="-",MID(A3,4,2),MID(A3,3,2))/60+IF(LEFT(A3,1)="-",MID(A3,6,2),MID(A3,5,2))/3600

Put this formula in Column C:

=IF(MID(A3,FIND(",",A3,1)+2,1)="-",MID(A3,FIND(",",A3,1)+2,4),MID(A3,FIND(",",A3,1) +2,3))+IF(MID(A3,FIND(",",A3,1)+2,1)="-",MID(A3,FIND(",",A3,1)+6,2),MID(A3,FIND(",",A3,1) +5,2))/60+IF(MID(A3,FIND(",",A3,1)+2,1)="-",MID(A3,FIND(",",A3,1)+8,2),MID(A3,FIND(",",A3,1) +7,2))/3600

Then drag the formula down however many rows of data you have to convert.
That should get you what you want.

Here's what I get in my test cases:

Lat/Long String Latitude Longitude
Decimal Decimal
390757, 0902243 39.13250 90.37861111
-390757, 0902243 -38.86750 90.37861111
390757, -0902243 39.13250 -89.62138889
-390757, -0902243 -38.86750 -89.62138889


HTH,

Eric

"Cheese" wrote:

Ah yes, good point.

All coordinates are within the United States, which means the latitude is
always N (+) and longitude is always W (-).

The minus sign in my decimal example was added by me. I thought maybe this
could be added later, if easier.


"EricG" wrote:

Need to know what general format these are in. For example, latitude can be
expressed as -90 to 90 degrees, or 0 to 180 degrees. Longitude can be -180
to 180 degrees or 0 to 360 degrees. And there are other formats as well.

Can either the lat or long parts have minus (-) signs?

Eric


"Cheese" wrote:

I have an Excel spreadsheet with Lat/Lon coordinates in an unusual format.

The Degrees, Minutes, Seconds are merged together as text, without spaces.
They're in two columns, like this:

Lat, Lon
390757, 0902243

These numbers are the equivalent of 39° 07' 57", 90° 22' 43". I want to
convert these columns to their decimal equivalents, like this: 39.1325°,
90.378611°.

I have Excel 2002.
Unfortunately, I'm clueless with Visual Basic. Macros I can handle.

Thanks!