How to tell excel in formula to calculate the difference in cells between the first previous non-blank cell and the next previous non-blank cell

TroubledFormula

New Member
Joined
May 19, 2020
Messages
3
Office Version
  1. 2016
Platform
  1. Windows
Dear All,

As a last resort I hope someone can help me out.

I require excel to calculate the difference in cells when a value a few rows below changes. The difference in amount of cells between the previous non-blank cell and next non-blank cell is a number I'll be using in another formula.
I've attached a small simple example. I know with index match function how to find the next non-blank cell but not how to find the previous non blank cell in a range.

Every tip is much appreciated and I thank you for your time.
 

Attachments

  • Difference between non-blank cells.png
    Difference between non-blank cells.png
    5.1 KB · Views: 14

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
This is how I would do it, I expect there are other ways.
Book1 (version 1).xlsb
ABCD
1Result
21102.5
32205
43307.5
5440008020
6512040
76103.333333
8770006020
Sheet2
Cell Formulas
RangeFormula
D2:D8D2=C2/(INDEX(FREQUENCY(IF($B$2:$B$8="",$A$2:$A$8),IF($B$2:$B$8<>"",$A$2:$A$8)),COUNTIF(B$1:B1,"<>")+1)+1)
Press CTRL+SHIFT+ENTER to enter array formulas surrounded with curly braces.
 
Upvote 0
This is how I would do it, I expect there are other ways.
Book1 (version 1).xlsb
ABCD
1Result
21102.5
32205
43307.5
5440008020
6512040
76103.333333
8770006020
Sheet2
Cell Formulas
RangeFormula
D2:D8D2=C2/(INDEX(FREQUENCY(IF($B$2:$B$8="",$A$2:$A$8),IF($B$2:$B$8<>"",$A$2:$A$8)),COUNTIF(B$1:B1,"<>")+1)+1)
Press CTRL+SHIFT+ENTER to enter array formulas surrounded with curly braces.

Thank you for your reply but if expand the range in your formula (Ive got 3000+ rows) than the result is a different value.
 
Upvote 0
It will still work if your data is consistent with the example.
I would need to see the expanded formula and an example where it is not giving the correct result in order to identify why it is not working as expected.
 
Upvote 0
I expect there are other ways.

@TroubledFormula
Welcome to the MrExcel board!

One of those other ways would be ..
(I assume that column B actually has a heading in row 1 so) insert a new row 2 and enter 0 in cells A2 & B2. You could then hide row 2 if you want.

20 05 19.xlsm
ABCD
1TextResult
200
31102.5
42205
53307.5
6440008020
7512040
86103.33333
9770006020
108 
119 
1210 
Count rows
Cell Formulas
RangeFormula
D3:D12D3=IF(C3="","",C3/(MATCH(TRUE,INDEX(B3:B$5000<>"",0),0)-1+A3-LOOKUP(9^99,B$2:B2,A$2:A2)))
 
Upvote 0
Thank you both for the solutions! I've managed to get both work in the file I have!

What a great service!
 
Upvote 0
You're welcome. Thanks for the follow-up. :)
 
Upvote 0
another solution for your reference
Book11.xlsx
ABCD
1ValueResult
21102.5
32205
43307.5
5440008020
6512040
76103.333333
8770006020
986020
1096020
111050006020
Sheet6
Cell Formulas
RangeFormula
D2:D11D2=C2/(MIN(IF(B2:B9999<>"",ROW(2:9999)))-MAX((B$1:B1<>"")*ROW($1:1)))
Press CTRL+SHIFT+ENTER to enter array formulas.
 
Upvote 0

Forum statistics

Threads
1,214,883
Messages
6,122,077
Members
449,064
Latest member
MattDRT

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top