Is there a better way to test a column for non-sequential numbers?

JenniferMurphy

Well-known Member
Joined
Jul 23, 2011
Messages
2,534
Office Version
  1. 365
Platform
  1. Windows
I need to check if a table column contains only the counting numbers (1, 2, 3, 4, ...) and blanks.

I found the KuTools add-in that claims to be able to do this. Does anyone have experience with this add-in? It says it contains over 300 other tools. I prefer to limit add-ins as much as possible to keep Excel clean and simple.

I then created this sheet which I thought did the job with a couple of helper cells and the duplicate values test. Here it is with four test columns. The Good column has correct values. The Dup column has duplicate values which the test finds and the duplicate values test highlights. The Gap column has a missing number, which the test detects, but it is not highlighted. The Oops column shows a failure of the test where there are two errors that add up to the correct sum. (sigh)

Sequential Numbers.xlsx
CDEF
4GoodDupGapOops
55555
6
72223
84443
9
101111
116576
12
133333
14
1521202221
166576
176666
18OKErrorErrorOK
Test
Cell Formulas
RangeFormula
C15C15=SUBTOTAL(109,[Good])
D15D15=SUBTOTAL(109,[Dup])
E15E15=SUBTOTAL(109,[Gap])
F15F15=SUBTOTAL(109,[Oops])
C16C16=MAX(TblSeq[Good])
D16D16=MAX(TblSeq[Dup])
E16E16=MAX(TblSeq[Gap])
F16F16=MAX(TblSeq[Oops])
C17C17=COUNT(TblSeq[Good])
D17D17=COUNT(TblSeq[Dup])
E17E17=COUNT(TblSeq[Gap])
F17F17=COUNT(TblSeq[Oops])
C18C18=IF(AND(C16=C17,TblSeq[[#Totals],[Good]]=(C16*(C16+1)/2)),"OK","Error")
D18D18=IF(AND(D16=D17,TblSeq[[#Totals],[Dup]]=(D16*(D16+1)/2)),"OK","Error")
E18E18=IF(AND(E16=E17,TblSeq[[#Totals],[Gap]]=(E16*(E16+1)/2)),"OK","Error")
F18F18=IF(AND(F16=F17,TblSeq[[#Totals],[Oops]]=(F16*(F16+1)/2)),"OK","Error")


I could write a VBA macro to load the list, sort it, and check it. I could then highlight the problem cells. But then I'd have to remember to run it.

Any comments?
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
Possibly this?

23 05 04.xlsm
ABCD
1GoodDupGapOops
25555
3
42223
54443
6
71111
86576
9
103333
11
12TRUEFALSEFALSEFALSE
Check Sequence
Cell Formulas
RangeFormula
A12A12=LET(r,TblSeq[Good],s,SORT(FILTER(r,r<>"")),AND(s=SEQUENCE(ROWS(s))))
B12B12=LET(r,TblSeq[Dup],s,SORT(FILTER(r,r<>"")),AND(s=SEQUENCE(ROWS(s))))
C12C12=LET(r,TblSeq[Gap],s,SORT(FILTER(r,r<>"")),AND(s=SEQUENCE(ROWS(s))))
D12D12=LET(r,TblSeq[Oops],s,SORT(FILTER(r,r<>"")),AND(s=SEQUENCE(ROWS(s))))
Cells with Conditional Formatting
CellConditionCell FormatStop If True
A2:D10Expression=AND(A2<>"",OR(COUNTIF(A$2:A$10,A2)>1,ISNA(MATCH(A2,SEQUENCE(COUNT(A$2:A$10)),0))))textNO
 
Upvote 0
Wow! That will take me a few minutes and a nap to understand. Thanks.
To break it down, I am really just doing three separate calculations, and then checking to see if the value if each is exactly the same.

This part calculates the number of unique entries (ignoring blanks):
Excel Formula:
SUM(IF(FREQUENCY(C5:C14,C5:C14)>0,1))

This part calculates the range (span) between the lowest and highest values:
Excel Formula:
MAX(C5:C14)-MIN(C5:C14)+1)

And then this part counts the total number of non-blank entries:
Excel Formula:
COUNT(C5:C14)

Then I am just using an AND function to check to see if all 3 values are equal to each other.
I am using a LET to simplify things, so I don't need to calculate the first value twice.

If all three are equal, then we know we have consecutive entries with no duplicates (as long as we are only dealing with whole numbers).
 
Upvote 0
To break it down, I am really just doing three separate calculations, and then checking to see if the value if each is exactly the same.

That's very helpful. I let myself get freaked out over the use of the Let function in most of the examples. After your breakdown, I broke down and checked it out. Very simple and very handy. One of the reasons I had eschewed in-cell formulas ad opted for VBA is the need to repeat complex expressions, which leads to errors. The Let function makes thay much easier.

Thank you
 
Upvote 0

Forum statistics

Threads
1,215,184
Messages
6,123,533
Members
449,106
Latest member
techog

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