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

JenniferMurphy

Well-known Member
Joined
Jul 23, 2011
Messages
2,687
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

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
For your row 18, I think the following formula should accurately identify which ones are good.
Place this formula in cell C18 and copy to D18:F18:
Excel Formula:
=LET(c,SUM(IF(FREQUENCY(C5:C14,C5:C14)>0,1)),IF(AND((MAX(C5:C14)-MIN(C5:C14)+1)=c,COUNT(C5:C14)=c),"OK","Error"))

1683142325216.png


Highlighting the "bad values" may prove to be a bit more tricky.
- How are you currently highlighting the duplicates now (are you using Conditional Formatting? if so, how exactly do you have it set up)?
- Should every column counter start with number 1?
- If not, how do we know which value should be highlighted?
For example, in your column E example, how do we know if the 1 or the 7 is the "bad" value if we do not know exactly what number our counter should start at?
 
Upvote 0
For your row 18, I think the following formula should accurately identify which ones are good.
Place this formula in cell C18 and copy to D18:F18:
Excel Formula:
=LET(c,SUM(IF(FREQUENCY(C5:C14,C5:C14)>0,1)),IF(AND((MAX(C5:C14)-MIN(C5:C14)+1)=c,COUNT(C5:C14)=c),"OK","Error"))
Wow! That will take me a few minutes and a nap to understand. Thanks.
 
Upvote 0
to get a count of all . Once typed use Ctrl-Shift_Enter
1683180482938.png
 
Upvote 0
Another option:
Book1
ABCD
1GoodDupGapOops
25555
3
42223
54443
6
71111
86576
9
103333
11
12OKErrorErrorError
Sheet1
Cell Formulas
RangeFormula
A12A12=LET(r,TblSeq[Good], f,SORT(FILTER(r,r<>"")), sq,SEQUENCE(ROWS(f),1,MIN(f),1), IF(SUM(IF(f=sq,1,0))=ROWS(f),"OK","Error"))
B12B12=LET(r,TblSeq[Dup], f,SORT(FILTER(r,r<>"")), sq,SEQUENCE(ROWS(f),1,MIN(f),1), IF(SUM(IF(f=sq,1,0))=ROWS(f),"OK","Error"))
C12C12=LET(r,TblSeq[Gap], f,SORT(FILTER(r,r<>"")), sq,SEQUENCE(ROWS(f),1,MIN(f),1), IF(SUM(IF(f=sq,1,0))=ROWS(f),"OK","Error"))
D12D12=LET(r,TblSeq[Oops], f,SORT(FILTER(r,r<>"")), sq,SEQUENCE(ROWS(f),1,MIN(f),1), IF(SUM(IF(f=sq,1,0))=ROWS(f),"OK","Error"))
 
Upvote 0
As for highlighting the issue cells, best i could come up with below:
Book1
ABCD
1GoodDupGapOops
25555
3
42223
54443
6
71111
86576
9
103333
11
12    
133
14
153
16
1757
Sheet1
Cell Formulas
RangeFormula
A12:A17A12=LET(r,TblSeq[Good], f,SORT(FILTER(r,r>0)), sq,SEQUENCE(ROWS(f),1,MIN(f),1), IF(f<>sq,f,""))
B12:B17B12=LET(r,TblSeq[Dup], f,SORT(FILTER(r,r>0)), sq,SEQUENCE(ROWS(f),1,MIN(f),1), IF(f<>sq,f,""))
C12:C17C12=LET(r,TblSeq[Gap], f,SORT(FILTER(r,r>0)), sq,SEQUENCE(ROWS(f),1,MIN(f),1), IF(f<>sq,f,""))
D12:D17D12=LET(r,TblSeq[Oops], f,SORT(FILTER(r,r>0)), sq,SEQUENCE(ROWS(f),1,MIN(f),1), IF(f<>sq,f,""))
Dynamic array formulas.
Cells with Conditional Formatting
CellConditionCell FormatStop If True
A2:D10Expression=IF(COUNTIF(A$12:A$17,A2)>0,TRUE,FALSE)textNO
 
Upvote 0
Tell a lie, i will leave it at the below:
Book1
ABCD
1GoodDupGapOops
25555
3
42223
54443
6
71111
86576
9
103333
Sheet2
Cells with Conditional Formatting
CellConditionCell FormatStop If True
A2:D10Expression=ISNUMBER(LET(r,A$2:A$10, f,SORT(FILTER(r,r<>"")), sq,SEQUENCE(ROWS(f),1,MIN(f),1), res,UNIQUE(IF(f<>sq,f,"")),MATCH(A2,FILTER(res,res<>""),0)))textNO
 
Upvote 0

Forum statistics

Threads
1,223,888
Messages
6,175,203
Members
452,617
Latest member
Narendra Babu D

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