Error in running a function to convert coordinates in degrees to decimal for EXCEL VBA

fazna ali

New Member
Joined
Nov 5, 2012
Messages
12
Dear all,

Currently I am working on VBA excel to create a widget to verify coordinates whether it lies under the radius of ANOTHER predefined and pre-specified sets of coordinates.

In the module, I want to convert the coordinates from degrees to decimal before doing the calculation - as the formula of the calculation only allow the decimal form of coordinates.

However, each and every time I want to run the macros this error (Run-time error '5', invalid procedure call or argument) will appear. Then, the debug button will bring me to below line of coding:

Code:
<code style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; white-space: inherit; background-image: initial; background-attachment: initial; background-size: initial; background-origin: initial; background-clip: initial; background-position: initial; background-repeat: initial;"> 
degrees = Val(Left(Degree_Deg, InStr([COLOR=#800000]1[/COLOR], Degree_Deg, [COLOR=#800000]"°"[/COLOR]) - [COLOR=#800000]1[/COLOR]))
</code>

For your information, the full function is as below:

Code:
<code style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; white-space: inherit; background-image: initial; background-attachment: initial; background-size: initial; background-origin: initial; background-clip: initial; background-position: initial; background-repeat: initial;">Function Convert_Decimal(Degree_Deg As String) As Double
'source: http://support.microsoft.com/kb/213449
   
   Dim degrees As Double
   Dim minutes As Double
   Dim seconds As Double
   '
   'modification by JLatham
   
   Degree_Deg = Replace(Degree_Deg, "~", "°")


   
   degrees = Val(Left(Degree_Deg, InStr(1, Degree_Deg, "°") - 1))
 
   minutes = Val(Mid(Degree_Deg, InStr(1, Degree_Deg, "°") + 2, _
             InStr(1, Degree_Deg, "'") - InStr(1, Degree_Deg, "°") - 2)) / 60
   
   seconds = Val(Mid(Degree_Deg, InStr(1, Degree_Deg, "'") + _
           2, Len(Degree_Deg) - InStr(1, Degree_Deg, "'") - 2)) / 3600


   Convert_Decimal = degrees + minutes + seconds
End Function
</code>


However, for your info, it's not only code that I use in the widget.

Besides, I'm not really sure whether the error is coming from the coding or from the data in the worksheet.

I hope I can share the workbook here so you can have overall idea on how the widget looks like.


Thank you.

Your kind assistance and attention in this matter are highly appreciated.

Regards,
Nina.
 
Last edited:

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
Cross-posted here: Error in running a function to convert coordinates in degrees to decimal for EXCEL VB

For reference, we do not forbid cross-posting at our forum. However we do require that you post references to cross-posts so that members here can keep tabs on other solutions offered. Please remember this in future.


It is noted Jon von der Heyden. I'm sorry because I did not read about the cross post earlier. Thank you for helping me post the link here. :)
 
Upvote 0

Forum statistics

Threads
1,215,432
Messages
6,124,860
Members
449,194
Latest member
HellScout

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top