简体   繁体   中英

What kind of code should I use to loop through DMS coordinates and convert them into Decimal Degree in Excel VBA?

I've got loads of coordinate data in excel listed as in DMS with a formatting as such for example:

893952N1001233.1
882222N0991244.4
... 
...

and so on and so on.

That data is in my Column A.

I treated that column as a text and had both coordinates separated by the "N" so that I could get both coordinate pieces in separate columns of Column B and Column C. (example: B1: 893952, C1: 1001233.1 ; B2: 882222 C2: 991244.4)

Since those numbers are in DMS, they are DDMMSS.S depending on whether or not they have decimals of course, some do, some don't. What code could I use that would read the DMS coordinates in columns B and C, then translate them into Decimal Degrees by taking the "SS.S" part of the value and divide it by 3600, take the MM part of the value and divide it by 60, and add it to the DD (sometimes DDD of course)?

I'd want the resultant coordinates to be posted in columns D and E.

So basically, I'd want it to read the coordinate, convert from DMS to Decimal degrees by using the method of DD+(MM/60)+(SS.S/3600), then loop through the remaining multitudes of coordinates.

I hope I made this clear enough, if it's not clear enough please tell me what I explained poorly and I'll attempt to explain! The wisdom of the good people on this site would be much appreciated!!

(If there is a simple function on Excel that would just convert this for me that I'm missing, I apologize ahead of time for missing, but I checked and I couldn't find one)

Enter the following in column 1 (each new line is a new row):

893952N1001233.1
=LEFT(A1,FIND("N",A1)-1)
=RIGHT(A1,LEN(A1)-FIND("N",A1))
=IF(OR(LEN(A2)=7,LEN(A2)=9),LEFT(A2,3)+MID(A2,4,2)/60+RIGHT(A2,LEN(A2)-5)/3600,LEFT(A2,2)+MID(A2,3,2)/60+RIGHT(A2,LEN(A2)-4)/3600)
=IF(OR(LEN(A3)=7,LEN(A3)=9),LEFT(A3,3)+MID(A3,4,2)/60+RIGHT(A3,LEN(A3)-5)/3600,LEFT(A3,2)+MID(A3,3,2)/60+RIGHT(A3,LEN(A3)-4)/3600)

Is that what you're looking for? Comment if not.

Of course, you'll have to set up your formulae appropriately for the layout of your data, this is just an example.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM