I want to fill in the blanks between these cells with the average difference: i.e., because there are 11
blank cells between 0.234
and 0.334
the first blank should be 0.234 + ((0.334 - 0.234) / 11)
. How can I write a formula to fill in those gaps automatically?
Google Sheets – How to Calculate Average Between Cells
google sheets
Related Topic
- Google Sheets – How to Calculate Average Days Between Multiple Dates
- Google-sheets – Average first 3 values excluding empty cells in google sheets
- Google-sheets – Sliding window average of last N non-empty non-blank cells in Google Sheets
- Google-sheets – Formula to ignore blank cells and calculate cells having numbers only
- Google Sheets – How to Count Random Average
- Google Sheets – ISBLANK Function Returning Unexpected Results
- Google-sheets – How to show blank cells instead of 0s in Google Sheets
Best Answer
In principle, this could be done without a script... but it's really ugly. Already looking up the nearest nonempty cells (up and down) is nontrivial (and slow), and it gets much worse when you start writing data into the column, thus changing what's empty or not (circular dependency). One could calculate in another column and then paste the values... but it's better to just use a script.
The script below adds a custom function "Interpolate" to the menu, when the document opens. Place the cursor to any cell within a gap, and use the menu command.
Although the function
interpolate()
looks long, the logic is very straightforward. Among the advantages of a script solution is robust handling of edge cases: there is no data above, there is no data below, the data isn't numeric, or the gap doesn't actually exist.