My sub createTrip() creates a new worksheet and a table within it.
It works basically fine, but I use this one function for all the data range cells. The function calculates distances between coordinates in the top rows and the left rows. The function itself has no mistakes:
=ARCCOS(SIN(E$3*PI()/180)*SIN($C5*PI()/180)+COS(E$3*PI()/180)*COS($C5*PI()/180)*COS(($D5*PI()/180)-(E$4*PI()/180)))*6367.4445
(I also tried to add the Worksheets name to it like =ARCCOS(SIN(Processing!E$3*PI()/1...
- without any success.)
The problem is, when my sub is done, there will be a #NAME
-error in all the data range cells.
The error will be removed by clicking into the cell, clicking into the formula-bar and clicking back onto the worksheet - without changing anything.
I tried to add some recalculation lines to my sub, but that does not help:
ws.EnableCalculation = False
ws.EnableCalculation = True
What else can I do?
The formula is applied to the cells with VBA like this:
Dim Pro As Worksheet
Set Pro = ThisWorkbook.Sheets("Processing")
// start for loop (ii)
// if maximum ii is reached:
With Pro
Set distanceRange = .Range(.Cells(5, 5), .Cells(ii + 6, ii + 6))
End With
distanceRange.Select
distanceRange.Formula = "=ARCCOS(SIN(E$3*PI()/180)*SIN($C5*PI()/180)+COS(E$3*PI()/180)*COS($C5*PI()/180)*COS(($D5*PI()/180)-(E$4*PI()/180)))*6367.4445"
Thanks for helping here!
ARCCOS
beACOS
? – user4039065ACOS
andACOSH
. – user4039065