Find First Missing Number > 990000

zero269

Active Member
Joined
Jan 16, 2023
Messages
253
Office Version
  1. 365
Platform
  1. Windows
Hello everyone,

I've been playing around with a few options that allow people to find missing numbers within a range of numbers.

One example is this one:
=SMALL(IF(ISNA(MATCH(ROW(A$1:A$30),A$1:A$30,0)),ROW(A$1:A$30)),ROW(A1))


The example above requires all values to be returned in a different column. I'm really just trying to get ONE number (the first/smallest missing number) … and only IF the number is greater than 990000.

I tried playing around with IF and MIN with the above formula, but no luck.

Brief details about my data:

I have two number ranges in my column I want to check against.
  1. Testable books (#'s <990000)
  2. Non-Testable Books (#'s >990000)
  • The Testable Books have assigned Quiz numbers that are not changeable.
  • The Non-Testable Books use my number range which starts at 990,000 as they do not conflict with the testable books range.
At times I find myself purging books from the master list… which consists of purging all data in the row to include the Quiz number in question.

If I purge a Non-Testable book, then I would like to reuse that number that's no longer in use. However, I do not always reuse it right away. Could be days or even weeks later.

Currently, I'm just using the MAX function +1 to show me what my Next Available Number is to use. However, if I can find the first (MIN) missing number greater than 990000, I think that would be optimal.

All the examples I've seen so far show a list of missing numbers. I'm hoping to get just that one number in a single cell if possible.

Any help or additional ideas would be greatly appreciated.

In the example below, I'm using a small sample of values for the number range I'm looking to find the first missing number in.

1674684633934.png
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
Based on your picture, I guessed that your data starts in cell B4 and ends in cell B13. Note that in the formula, you must specify an end of range greater than than the last data cell's row so that you can find the blank after it in case there are no blank cells within the range... that is why I used B14 as the end cell (although any number larger than 14 would work), not B13.

=1+INDEX(B:B,MIN(IF(B4:B14="",ROW(B4:B14)))-1)

EDIT NOTE: Just realized that you could have numbers less than 990000 in the column, so here is a modification to the above formula that will ignore such values...

=LET(r,INDEX(A:A,IF(A4:A16="",ROW(A4:A16))-1),n,IFERROR(r,),1+MIN(IF(n>990000,n)))
 
Last edited:
Upvote 0
and only IF the number is greater than 990000.
Based on your sample data, I'm not sure whether you are asking for the formula to actually check that?

23 01 26.xlsm
BCDEF
1
2
3
4990001990001990001990001800
5990002990002990002990002801
6990003990003802
7990004990004
8990005990005990005990005990001
9990006990006990006990006990002
10990007990007990007990007
11990008990008990008990008990004
12990009990009990009990009990005
13990010990010990010990010990006
14
15
16
17990011990003990003990004990003
Next Available
Cell Formulas
RangeFormula
B17:F17B17=LET(s,SEQUENCE(1000,,990001),AGGREGATE(15,6,s/ISNA(MATCH(s,B4:B14,0)),1))
 
Upvote 0
Solution
Or try

Book1
ABCDE
1
2
3
4990001990001990001990001800
5990002990002990002990002801
6990003990003802
7990004990004
8990005990005990005990005990001
9990006990006990006990006990002
10990007990007990007990007
11990008990008990008990008990004
12990009990009990009990009990005
13990010990010990010990010990006
14
15
16
17990011990003990003990004990003
Sheet1
Cell Formulas
RangeFormula
A17:E17A17=AGGREGATE(15,6,A4:A13/(A4:A13>990000)/(A5:A14=""),1)+1
 
Upvote 0
=LET(r,INDEX(A:A,IF(A4:A16="",ROW(A4:A16))-1),n,IFERROR(r,),1+MIN(IF(n>990000,n)))
Rick,

Thanks for taking the time to look into this for me. I tested your code and adjusted the ranges for each of my four Test Columns.
Unfortunately, the results were showing numbers that were not missing. See my screenshot below where I compared three different proposals in this thread.

Your code for the first test column:
Excel Formula:
=LET(r,INDEX($C$5:$C$18,IF($C$5:$C$18="",ROW($C$5:$C$18))-1),n,IFERROR(r,),1+MIN(IF(n>990000,n)))
Based on your sample data, I'm not sure whether you are asking for the formula to actually check that?
Peter,

I tried your code too and tailored it to each of the four test columns.
You code returned the first missing number that was greater than 990000... which PERFECT.
That's awesome that this was achievable using code that only "looks" simple when compared to others I've played with today.
Absolutely amazing!

Your code for the first test column:
Excel Formula:
=LET(s,SEQUENCE(1000,,990001),AGGREGATE(15,6,s/ISNA(MATCH(s,$C$5:$C$18,0)),1))

Thank you again for your time and expertise. I'm still working my way through the Learning VBA in Excel course on LinkedIn Learning and can't wait to get to the point where I can apply what I'm learning to my personal project.

Phuoc,
I tried your code too and adjusted the ranges for their respective columns. Unfortunately, it's producing #NUM errors for all four test columns.
Please see screenshot:

Your code for the first test column:
Excel Formula:
=AGGREGATE(15,6,$C$5:$C$18/($C$5:$C$18>990000)/($C$5:$C$18=""),1)+1



NOTE:
I added three numbers to each of the test columns that were below the range to validate it wouldn't return any numbers less than 990000.
Row 18 was used for first column only. The other three only went down to Row 17.

1674695518301.png
 
Upvote 0
I tested your code and adjusted the ranges for each of my four Test Columns.
.. but not correctly. Same for Phuoc's formula

(Also note that based on your samples, none of the formula require $ signs for any of the ranges)

23 01 26.xlsm
BCDEF
5100100100100
61000100010001000
710000100001000010000
8990001990001990001990001
9990002990002990002990002
10990003990003
11990004990004
12990005990005990005990005
13990006990006990006990006
14990007990007990007990007
15990008990008990008990008
16990009990009990009990009
17990010990010990010990010
18
19
20
21Rick990011990003990003990004
22Peter990011990003990003990004
23Phuoc990011990003990003990004
Next Available (2)
Cell Formulas
RangeFormula
C21:F21C21=LET(r,INDEX(C:C,IF(C5:C18="",ROW(C5:C18))-1),n,IFERROR(r,),1+MIN(IF(n>990000,n)))
C22:F22C22=LET(s,SEQUENCE(1000,,990001),AGGREGATE(15,6,s/ISNA(MATCH(s,C5:C19,0)),1))
C23:F23C23=AGGREGATE(15,6,C5:C17/(C5:C17>990000)/(C6:C18=""),1)+1
 
Upvote 0
Phuoc,
Your code for the first test column:
Excel Formula:
=AGGREGATE(15,6,$C$5:$C$18/($C$5:$C$18>990000)/($C$5:$C$18=""),1)+1
No, it's not . Should be:


=AGGREGATE(15,6,$C$5:$C$18/($C$5:$C$18>990000)/($C$6:$C$19=""),1)+1
 
Upvote 0
Hi Peter,
.. but not correctly. Same for Phuoc's formula
Good catch! (y)
I didn't realize that some started at Row 4 and 5 at the top... I made corrections and all but one is working now... but that's only due to a conflict with values above and below the Table in my original workbook.
(Also note that based on your samples, none of the formula require $ signs for any of the ranges)
Out of habit I locked the ranges... I didn't foresee any potential conflicts.
1674700313040.png

I can't use the one that results in 1 above because it references the entire column and I have values below the Table in my original workbook.
 
Last edited:
Upvote 0
No, it's not . Should be:


=AGGREGATE(15,6,$C$5:$C$18/($C$5:$C$18>990000)/($C$6:$C$19=""),1)+1
Sorry about that. Peter noticed that too and I was able to correct my testing...
 
Upvote 0
I can't use the one that results in 1 above because it references the entire column and I have values below the Table in my original workbook.
How is that a problem?

23 01 26.xlsm
BC
1
2
3
4
5100
61000
710000
8990001
9990002
10990003
11990004
12990005
13990006
14990007
15990008
16990009
17990010
18
19
20
21Rick990011
22Peter990011
23Phuoc990011
24
25Data
265000000
2756
28990011
29990012
Next Available (2)
Cell Formulas
RangeFormula
C21C21=LET(r,INDEX(C:C,IF(C5:C18="",ROW(C5:C18))-1),n,IFERROR(r,),1+MIN(IF(n>990000,n)))
C22C22=LET(s,SEQUENCE(1000,,990001),AGGREGATE(15,6,s/ISNA(MATCH(s,C5:C19,0)),1))
C23C23=AGGREGATE(15,6,C5:C17/(C5:C17>990000)/(C6:C18=""),1)+1
 
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,849
Members
452,361
Latest member
d3ad3y3

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