How do I write an excel macro that will calculate the cumulative distance between points -


I am trying to write an Excel macro which is the cumulative distance between points based on their X and Y coordinate Will calculate. Here is an example of my current worksheet set-up:

  point # code x coordinate y coordinate points cumulative distance between 1 1 39.4 99.8 0 2 1 42.5 104.5? 3 1 43.0 105.8? 4 2 34.0 150.5? 5 3 38.9 145.9? 6 1 46.2 103.4? 7 1 48.5 105.3? 8 4 67.6 98.5? 9 1 50.3 103.2?  

Use the Pythagoras formula = SQRT ((D2-D1) ^ 2) to calculate the distance between the point and the previous point "Cumulative distance between points" " is required. + ((C2-C1) ^ 2)))) . For each subsequent value of "cumulative distance" between the column of value, the distance between the previous digits should be calculated and the total distance calculated to be calculated will be added to the total

Here the kicker is I I want to calculate the distance between only two points if both have a code of "1". If you look at your example then you can see that I have a code with values ​​between 1-4.

In the above example, I want to calculate the distance between point # 2 and 1. Next, I will calculate the distance between point # 3 and 2, and add it to the value obtained from the previous cell in the column (= Distance between point # 2 and 1). After this I will leave points 4 and 5 because they do not have the code = "1" The next counting point will be between # 6 and 3, because both have code- leaving "1" number 8 as code = "4" Will be given then calculate the distance between point # 9 and 7. Keep in mind that every time the "value points" column is calculated at a cumulative distance, it should be a cumulative value that adds all the previous values ​​to it

Then to wrap it, I need the following :

- Calculate the distance between the digits in the "Cumulative distance between the points" column (using the x, y coordinate) when both codes = 1. Get the total distance to last cumulative distance running To add cell value to.

I hope it is clear, if not, then I can confuse in any empty place.

You can do the worksheet with some extra columns though.

1) Create two new columns "Copy X" and "Copy Y" to keep the formulas in these columns, if one line has code 1, then x and Y copy the columns. For any other code, copy the value of copied x and y from the previous line, use the Excel if function to do this .

2) Calculate the difference between cumulative dragonism on all "copied x" and "copied y". This will add zero contribute to any row with 1 to second. This is the last column you add.


Comments