Question

I have the following excel spreadsheet:

enter image description here

The elevation is increasing in ascending order. The distance is culmulative. Criteria is a separate formula which can be explained here:

Selecting values in a list based on an interval?

I want to calculate the slope which is the difference in elevation divided by the difference in distance, but only for the values that have a criteria of "1". Here is a picture showing the spreadsheet filtered and cut where I get the expected values of slope:

enter image description here

I want to perform this formula on the unfiltered list and to get the desired result in the third image.

enter image description here

Are there any formula operations in excel that can perform this task? Can it be done in VBA?

Was it helpful?

Solution

You can add 2 helper columns to your table like so:

enter image description here

Col D tracks the last Elevation that met your criteria. Similarly, Col E selects the last Distance that met your criteria. This keep COL F's formula super simple.

Note this is a variation on Alan's comment, but I prefer the legibility and maintainability of the additional columns to the expert level (and lengthy) formula.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top