Find the nearest non blank cell in a row

BMPeers

New Member
Joined
Nov 5, 2004
Messages
36
I have a problem which I have been trying to solve but I need help.
Thanks in advance for any answers.

I have time series data, much of which is in complete. So for example there might be 4 years missing in the series. What I'd like is a formula which finds the nearest non-blank value both forward or backwards in time.

So for my example below, I'd like cells G2 and H2 to equal 21, and I2 and J2 to equal 51.

The formulas will be entered from row 9 downwards as a complete matrix.

2cpvkuc.jpg


Note my real dataset is many thousands of rows and more years...
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
I only know how to fill in the blank cells in each row with the last number that appeared in a non-blank cell. In your data, G2 through J2 would contain 21. I'm not sure how you'd discriminate between 'going forward' and 'going backwards.' Perhaps someone more clever can noodle it out.

Excel 2012
ABCDEFGHIJKLMNOPQ
11965196619671968196919701971197219731974197519761977197819791980
2dog427866917465291442178850
3cat4751529621302184314044836157352
4sheep1482379918722982974
5chicken59729874464131592612
6fox568441706414395697392354965496
7
8dog42786691747474747465291442178850
9cat4751529621302184314044836157352
10sheep1482379918787878787878722982974
11chicken59729874464141414141414131592612
12fox568441706414395697392354965496

<colgroup><col><col><col><col><col><col><col><col><col><col><col><col><col><col><col><col><col><col></colgroup><thead>
</thead><tbody>
</tbody>
Sheet31

Worksheet Formulas
CellFormula
B8=LOOKUP(2,1/(NOT(ISBLANK($B2:B2))),$B2:B2)
C8=LOOKUP(2,1/(NOT(ISBLANK($B2:C2))),$B2:C2)
D8=LOOKUP(2,1/(NOT(ISBLANK($B2:D2))),$B2:D2)
E8=LOOKUP(2,1/(NOT(ISBLANK($B2:E2))),$B2:E2)
F8=LOOKUP(2,1/(NOT(ISBLANK($B2:F2))),$B2:F2)
G8=LOOKUP(2,1/(NOT(ISBLANK($B2:G2))),$B2:G2)
H8=LOOKUP(2,1/(NOT(ISBLANK($B2:H2))),$B2:H2)
I8=LOOKUP(2,1/(NOT(ISBLANK($B2:I2))),$B2:I2)
J8=LOOKUP(2,1/(NOT(ISBLANK($B2:J2))),$B2:J2)
K8=LOOKUP(2,1/(NOT(ISBLANK($B2:K2))),$B2:K2)
L8=LOOKUP(2,1/(NOT(ISBLANK($B2:L2))),$B2:L2)
M8=LOOKUP(2,1/(NOT(ISBLANK($B2:M2))),$B2:M2)
N8=LOOKUP(2,1/(NOT(ISBLANK($B2:N2))),$B2:N2)
O8=LOOKUP(2,1/(NOT(ISBLANK($B2:O2))),$B2:O2)
P8=LOOKUP(2,1/(NOT(ISBLANK($B2:P2))),$B2:P2)
Q8=LOOKUP(2,1/(NOT(ISBLANK($B2:Q2))),$B2:Q2)

<thead>
</thead><tbody>
</tbody>

<tbody>
</tbody>
 
Upvote 0

Forum statistics

Threads
1,215,043
Messages
6,122,825
Members
449,096
Latest member
Erald

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