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

[TABLE="width: 100"]
<tbody>[TR]
[TD][/TD]
[TD]A[/TD]
[TD]B[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]0[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]0[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD]1[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]4[/TD]
[TD]0[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]5[/TD]
[TD]0[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]6[/TD]
[TD]1[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]7[/TD]
[TD]0[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]8[/TD]
[TD]0[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]9[/TD]
[TD]0[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]10[/TD]
[TD]1[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]11[/TD]
[TD]0[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]12[/TD]
[TD]1[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]13[/TD]
[TD]0[/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]



Table I need to create after VBA/Formula is applied

[TABLE="width: 100"]
<tbody>[TR]
[TD][/TD]
[TD]A[/TD]
[TD]B[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]0[/TD]
[TD]0[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]0[/TD]
[TD]0[/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD]1[/TD]
[TD]1[/TD]
[/TR]
[TR]
[TD]4[/TD]
[TD]0[/TD]
[TD]1[/TD]
[/TR]
[TR]
[TD]5[/TD]
[TD]0[/TD]
[TD]1[/TD]
[/TR]
[TR]
[TD]6[/TD]
[TD]1[/TD]
[TD]1[/TD]
[/TR]
[TR]
[TD]7[/TD]
[TD]0[/TD]
[TD]0[/TD]
[/TR]
[TR]
[TD]8[/TD]
[TD]0[/TD]
[TD]0[/TD]
[/TR]
[TR]
[TD]9[/TD]
[TD]0[/TD]
[TD]0[/TD]
[/TR]
[TR]
[TD]10[/TD]
[TD]1[/TD]
[TD]1[/TD]
[/TR]
[TR]
[TD]11[/TD]
[TD]0[/TD]
[TD]1[/TD]
[/TR]
[TR]
[TD]12[/TD]
[TD]1[/TD]
[TD]1[/TD]
[/TR]
[TR]
[TD]13[/TD]
[TD]0[/TD]
[TD]0[/TD]
[/TR]
</tbody>[/TABLE]



Any help would be greatly appreciated.

-R
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
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
[TABLE="width: 85%"]
<tbody>[TR]
[TD]Worksheet Formulas[TABLE="width: 100%"]
<thead>[TR="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=DAE7F5]#DAE7F5[/URL] "]
[TH="width: 10px"]Cell[/TH]
[TH="align: left"]Formula[/TH]
[/TR]
</thead><tbody>[TR]
[TH="width: 10px, bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=DAE7F5]#DAE7F5[/URL] "]B1[/TH]
[TD="align: left"]=IF(A1=1,1,IF(ISODD(COUNTIF(A$1:A1,1)),1,0))[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[/TR]
</tbody>[/TABLE]
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
Or

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

Forum statistics

Threads
1,225,749
Messages
6,186,802
Members
453,373
Latest member
Ereha

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