Replacing zeros with boundary numbers

hasanlianar

New Member
Joined
Jul 21, 2011
Messages
43
Hello,

I have rows of numbers as shown in the following examples:

1 0 0 0 1 0 0 0 0
0 0 0 2 0 0 2 0 0
3 0 3 0 0 0 0 0 0

I want to come up with a dynamic formula to fill zeros with boundary numbers. The result should be following:

1 1 1 1 1 0 0 0 0
0 0 0 2 2 2 2 0 0
3 3 3 0 0 0 0 0 0

I would appreciate if anyone could help,

Anar
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
Are you looking to do this in another location, or over top of the existing data?

If over top the existing data, note that cells can have hard-coded values, or formulas in them, but never both at the same time. So if you want to do it over top the existing data, it will probably require VBA.
Are you OK with that?

Also, will the boundaries ALWAYS be matching?
For example, could you have something like this:
1 0 0 2 0 0 0 0 0

If so, what happens in that case?

And, will there only ever be 2 non-zero values in each row?
 
Last edited:
Upvote 0
I want to do this in another location. I highly prefer non-VBA solution - with formulas
Boundaries will always match, i.e. boundaries will always be the same number (1-1, 2-2, 3-3, etc.)
There will always be 2 non-zero values.
 
Upvote 0
b​
c​
d​
e​
f​
g​
h​
i​
j​
k​
l​
m​
n​
o​
p​
q​
r​
s​
t​
u​
2​
0​
0​
0​
1​
0​
0​
0​
0​
1​
1​
1​
1​
1​
0​
0​
0​
0​
k2: =if(a2 > 0, a2, (countif($a2:a2, ">0") = 1) * max($a2:$i2))
3​
0​
0​
2​
0​
0​
2​
0​
0​
0​
0​
0​
2​
2​
2​
2​
0​
0​
4​
0​
3​
0​
0​
0​
0​
0​
0​
3​
3​
3​
0​
0​
0​
0​
0​
0​
 
Upvote 0

Forum statistics

Threads
1,214,983
Messages
6,122,582
Members
449,089
Latest member
Motoracer88

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