Counting rows based on data

nryan

Board Regular
Joined
Apr 3, 2015
Messages
61
Hello,

I'm trying to create a formula for column C in the examples below.
  • Column B is static, it never changes. I included it in case there's a clever way to use it that I'm not seeing.
  • Column A is input by the user.

I've been at it for a while and can't find a solution. Basically I want column C to start counting when the Column A has a value of 1 and continue counting until the last none zero value. There will never be more than 25 rows. Thanks in advance.

Example 1
[TABLE="width: 265"]
<tbody>[TR]
[TD][/TD]
[TD]A[/TD]
[TD]B[/TD]
[TD]C[/TD]
[TD]Notes[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]Contact #[/TD]
[TD]Pin #[/TD]
[TD]Location #[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]0[/TD]
[TD]1[/TD]
[TD]0[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD]1[/TD]
[TD]2[/TD]
[TD]1[/TD]
[TD]start counting[/TD]
[/TR]
[TR]
[TD]4[/TD]
[TD]2[/TD]
[TD]3[/TD]
[TD]2[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]5[/TD]
[TD]3[/TD]
[TD]4[/TD]
[TD]3[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]6[/TD]
[TD]0[/TD]
[TD]5[/TD]
[TD]4[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]7[/TD]
[TD]4[/TD]
[TD]6[/TD]
[TD]5[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]8[/TD]
[TD]0[/TD]
[TD]7[/TD]
[TD]6[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]9[/TD]
[TD]0[/TD]
[TD]8[/TD]
[TD]7[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]10[/TD]
[TD]0[/TD]
[TD]9[/TD]
[TD]8[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]11[/TD]
[TD]0[/TD]
[TD]10[/TD]
[TD]9[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]12[/TD]
[TD]0[/TD]
[TD]11[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13[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]17[/TD]
[TD]10[/TD]
[TD]16[/TD]
[TD]14[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]18[/TD]
[TD]11[/TD]
[TD]17[/TD]
[TD]15[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]19[/TD]
[TD]0[/TD]
[TD]18[/TD]
[TD]16[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]20[/TD]
[TD]13[/TD]
[TD]19[/TD]
[TD]17[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]21[/TD]
[TD]14[/TD]
[TD]20[/TD]
[TD]18[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]22[/TD]
[TD]0[/TD]
[TD]21[/TD]
[TD]19[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]23[/TD]
[TD]15[/TD]
[TD]22[/TD]
[TD]20[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]24[/TD]
[TD]16[/TD]
[TD]23[/TD]
[TD]21[/TD]
[TD]stop counting[/TD]
[/TR]
[TR]
[TD]25[/TD]
[TD]0[/TD]
[TD]24[/TD]
[TD]0[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]26[/TD]
[TD]0[/TD]
[TD]25[/TD]
[TD]0[/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
This works great! I like the way you used the SUM function to add a value of 1 to the value in the cell above. Lot cleaner than what I was doing. I think I understand what you did here with the AND and COUNTIF functions.

Thank you,
Nick
 
Upvote 0

Forum statistics

Threads
1,223,900
Messages
6,175,276
Members
452,629
Latest member
SahilPolekar

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