I am using excel 2016 on a mac(OS12.4)
I am trying to calculate the distance between points in lat long from data from an apple watch. I have downloaded the lat longs from the watch into a spreadsheet and have use the equation distxy=.... in the code below in a module and it ran a few times and gave the right answers (as far as I could tell).
I then copied the equation in another module and it ran several times without a problem but then stopped running. Now when I try to run the sub, I get a "Runtime error 1004. Method Acos of object WorksheetFunction failed" at he the equation. If I run the sub by stepping into it line by line, at the equation, I get an error"Runtime error 6. Overflow".
Can someone explain why I get two different errors and what I can do do fix the problem.
Thanks
I am trying to calculate the distance between points in lat long from data from an apple watch. I have downloaded the lat longs from the watch into a spreadsheet and have use the equation distxy=.... in the code below in a module and it ran a few times and gave the right answers (as far as I could tell).
I then copied the equation in another module and it ran several times without a problem but then stopped running. Now when I try to run the sub, I get a "Runtime error 1004. Method Acos of object WorksheetFunction failed" at he the equation. If I run the sub by stepping into it line by line, at the equation, I get an error"Runtime error 6. Overflow".
Can someone explain why I get two different errors and what I can do do fix the problem.
Thanks
Sub testgps()
Dim wf As WorksheetFunction
Dim lat1, lat2, long1, long2 As Double
Dim distxy As Double
Dim Radius As Single
Set wf = Application.WorksheetFunction
Radius = 6371
Worksheets("data").Activate
lastrow = ActiveSheet.Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
For i = 3 To lastrow
lat1 = Cells(i, "b").Value
lat2 = Cells(i - 1, "b").Value
long1 = Cells(i, "c").Value
long2 = Cells(i - 1, "c").Value
distxy = wf.Acos(Cos(wf.Radians(90 - lat1)) * Cos(wf.Radians(90 - lat2)) _
+ Sin(wf.Radians(90 - lat1)) * Sin(wf.Radians(90 - lat2)) _
* Cos(wf.Radians(long1 - long2))) * Radius * 1000
Cells(i, "j").Value = distxy
Next i
End Sub