in-filling a column with 1's & 0's

hissonrr

Board Regular
Joined
Feb 6, 2016
Messages
106
Good day all,

I was having some trouble and wasn't sure if i needed a VBA solution or could actually achieve the result I want with a formula of some kind.

basically i have a column of 1s and 0s like column A in the table below. What I need to happen is to create a new Column B that recognized the first instance a 1 occurs and then infill it to the next instance a 1 occurs, then continue on doing it multiple times down the column.

For example...

Initial Table

AB
10
20
31
40
50
61
70
80
90
101
110
121
130

<tbody>
</tbody>



Table I need to create after VBA/Formula is applied

AB
100
200
311
401
501
611
700
800
900
1011
1101
1211
1300

<tbody>
</tbody>



Any help would be greatly appreciated.

-R
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
Hi,

This is one way to do it with a formula:


Book1
AB
100
200
311
401
501
611
700
800
900
1011
1101
1211
1300
Sheet122
Cell Formulas
RangeFormula
B1=IF(A1=1,1,IF(ISODD(COUNTIF(A$1:A1,1)),1,0))


B1 formula copied down.
 
Upvote 0
Worksheet Formulas
CellFormula
B1=IF(A1=1,1,IF(ISODD(COUNTIF(A$1:A1,1)),1,0))

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

<tbody>
</tbody>
You can shorten that formula slightly...

=IF(A1=1,1,0+ISODD(COUNTIF(A$1:A1,1)))
 
Upvote 0
Thanks a lot guys I didn't even know the ISODD function existed.

i appreciate it consider this solved.
 
Upvote 0
You're welcome, glad to help.
 
Upvote 0
Or

=IF(A1=1,1,MOD(SUM(A$1:A1),2))
 
Upvote 0

Forum statistics

Threads
1,214,886
Messages
6,122,093
Members
449,064
Latest member
Danger_SF

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