Solved

Concerting Degrees, Minutes, Seconds to Decimal Degress Using A Function or Macro in Excel 2007

Posted on 2012-04-01
4
470 Views
Last Modified: 2012-09-20
Hi,

I had excellent help from EE with a code to convert degrees, minutes, seconds to decimal degrees. It worked beautifully with Excel 2010.

However, now one of my partners is using Excel 2007 and the code won't work. It just says, "ambiguous name detected decdeg."

I have attached that worksheet.

Any ideas why it won't work in 2007?

Best,
Kannika
dms-sample-excel-2007.xlsm
0
Comment
Question by:kannika
  • 2
4 Comments
 
LVL 43

Expert Comment

by:Saqib Husain, Syed
ID: 37794540
If you look at the code you will see module1, module2 and module3. Each of these modules has an instance of decdeg. Keep only one and delete the others.
0
 
LVL 78

Accepted Solution

by:
David Johnson, CD, MVP earned 500 total points
ID: 37795312
Public Function MyDecDeg(cl As Range)
    Dim pos1 As Long, pos2 As Long
    Dim pos3 As Long
   
    Dim deg As Double, min As Double, sec As Double
           
    pos1 = InStr(1, cl.Value, "°") 'degree character
    pos2 = InStr(pos1 + 1, cl.Value, Chr(146)) 'dipthong character
    pos3 = InStr(pos2 + 1, cl.Value, Chr(148)) 'right quotation character
               
    deg = Val(Mid(cl.Value, 1, pos1 - 1))
    min = Val(Mid(cl.Value, pos1 + 1, pos2 - 1))
    sec = Val(Mid(cl.Value, pos2 + 1, pos3 - 1))
               
    MyDecDeg = deg + Val(min & Format(sec / 60, ".0000")) / 60
End Function


It still doesn't work on my system but pos2 <> post2 and pos3 was not defined
0
 

Author Comment

by:kannika
ID: 37795916
Hi,

I got it.  I first deleted the three modules as suggested by ssaqibh.

The reason the code didn't work is because the sample data provided me last week has smart apostrophes and quotes while the real data provided today has straight apostrophes and quotes. So the code with Chr(146) and Chr(148) had to be changed to Chr(39) and Chr(34) respectively. I also changed "°" to Chr(176) for uniformity.  The devil is in the detail!

There is also some data inconsistency in that sometimes two apostrophes are used instead of a single quote. I am urging the client to collect digital coordinates rather than DMS, but there is some pushback (the old "We've always done it that way and can't change now").

Nonetheless, I really appreciate all the comments and help on this, as it increased my understanding of coding in Excel.  

Regards,
Kannika
0
 

Author Closing Comment

by:kannika
ID: 38420560
I apologize for not completing this thread sooner. I thought I had already completed it.

Best,
kannika
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Improved? Move/Copy Add-in Replacement - How to avoid the annoying, “A formula or sheet you want to move or copy contains the name XXX, which already exists on the destination worksheet.” David Miller (dlmille)  It was one of those days… I wa…
My experience with Windows 10 over a one year period and suggestions for smooth operation
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now