I'm working on an Excel sheet and struggling with a formula that I need help with. I hope someone here can guide me in the right direction!
My Goal: I want to calculate values in column H based on data in column G. The calculation needs to handle three different scenarios:
- If
Ghas a value: Simply use the difference between the current value and the previous non-blank value in column G. - If
Gis blank: Interpolate a value based on the difference between the last non-blank value above and the next non-blank value below, evenly distributing the difference across all blank cells in between. - If the cell above
His not a number: In such cases, I need the formula to take the value from theGcolumn directly.
Currently, I'm using this formula in cell H6, which is adapted from another file:
=IF(ISBLANK(G6),
IF(ISNUMBER(H5),
IFERROR(
(INDEX(G:G, MATCH(TRUE, INDEX(ISNUMBER(G7:G$100), 0), 0) + ROW()) - INDEX(G:G, MAX(IF(G$1:G5<>"", ROW(G$1:G5)))))
/ (MATCH(TRUE, INDEX(ISNUMBER(G7:G$100), 0), 0) + ROW() - MAX(IF(G$1:G5<>"", ROW(G$1:G5)))), 0),
G5),
G6 - IFERROR(INDEX(G:G, MAX(IF(G$1:G5<>"", ROW(G$1:G5)))), 0)
)
The Issue: This formula works for some scenarios but is not quite giving me the right results in every case. Specifically, I'm seeing errors when it comes to handling the interpolation correctly, especially when the next non-blank value is far down the column or if the cell above doesn't contain a number.
Mock Example Table: Here is a mock example of what my data looks like, to make it easier to understand:
| Day | Water Add (Column G) | Net Water (Column H) |
|---|---|---|
| 1 | 80 | 80 |
| 2 | 90 | 10 |
| 3 | 62 | |
| 4 | 62 | |
| 5 | 62 | |
| 6 | 62 | |
| 7 | 400 | 310 |
| 8 | 166.67 | |
| 9 | 166.67 | |
| 10 | 900 | 500 |
| 11 | 1100 | 200 |
What I Need: I need help modifying or correcting this formula so it consistently handles:
- Differences between consecutive non-blank cells in column G.
- Proper interpolation for blank cells.
- Graceful fallback to the value in column G if the cell above in column H is not a number.
Any help would be greatly appreciated!
Thanks so much in advance for your time and expertise!
Best, barc
I tried using the formula mentioned above in cell H6. I expected it to handle all the scenarios consistently: calculating the difference for consecutive non-blank cells, interpolating when there are blank cells between two non-blank values, and falling back to the value in column G if the previous cell in column H was not a number. However, I'm seeing incorrect values, especially when it comes to interpolation, or when there are gaps between values that span multiple rows.


H2) and will spill the results. Does H need to have text entries in some cells? ("If the cell above H is not a number")