counter column

SQUIDD

Well-known Member
Joined
Jan 2, 2009
Messages
2,104
Office Version
  1. 2019
  2. 2016
Platform
  1. Windows
Hi

I am trying to create a counter in column C.
Like this the counter counts from 1-8 only if column A has data. It resets if column B has data to 1 and starts over.
ABCDEFGHI
121
232
363
414
545
616
747
828
9
10
11431
12
13451
1422
1553
1634
17
1865
19

<tbody>
</tbody>

Thanks

Dave
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
Hi AliGW

Thanks for looking, I have put your formula in as you described.

All I seem to get is a 1 in column C if it finds data in column B??

Dave
 
Upvote 0
Hi

I am trying to create a counter in column C.
Like this the counter counts from 1-8 only if column A has data. It resets if column B has data to 1 and starts over.
ABCDEFGHI
121
232
363
414
545
616
747
828
999
??
10
11431
12
13451
1422
1553
1634
17
1865
19

<tbody>
</tbody>

Because you said "...the counter counts from 1-8 only if column A has data...", your question is not entirely clear as to what should happen if your have nine or more consecutive numbers in Column A with a number in Column B. For example, if there was a value in Column A where I have put my red 99, what should go in Column C where I put the double red question marks... 1 or 9? Assuming the answer is 1, put a 1 in cell C1, then put this formula in cell C2 and copy it down to the end of your data...

=IF(LEN(B2),1,IF(LEN(A2),MOD(LOOKUP(9E+307,C$1:C1,C$1:C1),8)+1,""))


EDIT NOTE: If, on the other hand, it should keep counting past 8, then use this formula instead...

=IF(LEN(B2),1,IF(LEN(A2),LOOKUP(9E+307,C$1:C1,C$1:C1)+1,""))
 
Last edited:
Upvote 0
With 1 in C1, put this into C2 and copy down:

=IF(AND(A2="",B2=""),"",IF(AND(A2<>"",B2<>""),1,C1+1))
 
Upvote 0
Hi Rick

many thanks.
Yes, in your example above, it should be 1 and not 9.
But if i do put a 99 in my data as you have, cell C11 should now be a 2, this is because B9 has no data.

Dave
 
Upvote 0
AliGW

many thanks again

I have done as you suggested, it works correct for the data that i posted, but if you in fact put a 99 where Rick suggested, the counter goes to 9, where it should be 1.

Below is Ricks example and expected results.

cheers


ABCDEFGHI
121
232
363
414
545
616
747
828
999
1
10
11432
12
13451
1422
1553
1634
17
1865
19

<tbody>
</tbody>
 
Upvote 0
Hi Rick

many thanks.
Yes, in your example above, it should be 1 and not 9.
But if i do put a 99 in my data as you have, cell C11 should now be a 2, this is because B9 has no data.
Try the first formula that I posted... that is exactly what it does (I did not modify your entire posted chart to show that because I was asking a question I did not know the answer to).
 
Upvote 0
Hi Rick

On my original data set, your formula works perfect, but if i do put in 99 as you did(which could happen) C11 become incorrect, displaying a 1 instead of 2.

Dave
 
Upvote 0

Forum statistics

Threads
1,214,950
Messages
6,122,438
Members
449,083
Latest member
Ava19

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