Function to find next missing number?

Rob*

Board Regular
Joined
Apr 23, 2010
Messages
82
Is there any function that can return the next missing number from a column with ascending numbers?
The highest number can be anything and there can be several numbers missing after each other.
Also the same number will not appear twice.
I only need to find the next missing number.

Code:
Ex:
-| A | B |
1| 1 | (Function to return "3")
2| 2 |
3| 4 |
4| 7 |
5| 8 |
6| 9 |
7|   |
8|
9|
Or if no function works, I can use VBA, but prefer not.
 
Last edited:
Does the list of numbers always start in cell A5? If so, does this adaptation of Ron's first standard formula do the job?

=IF(A5=1,INDEX(A5:A1005,MATCH(1,INDEX(--((A6:A1005-A5:A1004)<>1),0),0))+1,1)
 
Upvote 0

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Try this formula...
Code:
=LOOKUP(2,1/(A5:A1005=(ROW(A5:A1005)-ROW(A5)+1)),A5:A1005)+1
Is that something you can work with?

Yay! This seem to work after struggeling with translate it to my language ;)
Code:
=LETAUPP(2;1/(A5:A1005=(RAD(A5:A1005)-RAD(A5)+1));A5:A1005)+1
 
Last edited:
Upvote 0
How about this array-entered** formula...

=MIN(IF(A6:A1006-A5:A1005>1,A5:A1005+1))

**Commit this formula using CTRL+SHIFT+ENTER and not just Enter by itself.
 
Last edited:
Upvote 0
Doesn't that error if 1 is not the first number?

Yes...it would need a "missing 1" trap
Excel 2007 or later
Code:
=IFERROR(LOOKUP(2,1/(A5:A1005=(ROW(A5:A1005)-ROW(A5)+1)),A5:A1005)+1,1)
)

Pre-Excel 2007
Code:
=IF(A5<>1,1,LOOKUP(2,1/(A5:A1005=(ROW(A5:A1005)-ROW(A5)+1)),A5:A1005)+1)

EDITED TO INCLUDE THIS ALTERNATIVE:
Since we do know where the range starts, I suppose this abbreviated regular formula could be used:
Code:
=IF(A5=1,LOOKUP(2,1/(A5:A1005=(ROW(A5:A1005)-4)),A5:A1005)+1,1)
 
Last edited:
Upvote 0
How about this array-entered** formula...

=MIN(IF(A6:A1006-A5:A1005>1,A5:A1005+1))

**Commit this formula using CTRL+SHIFT+ENTER and not just Enter by itself.
Noting Peter's comment on another message... my formula would have trouble if A5 is not a 1, so use this array-entered formula instead...

=IF(A5<>1,1,MIN(IF(A6:A1006-A5:A1005>1,A5:A1005+1)))

**Commit this formula using CTRL+SHIFT+ENTER and not just Enter by itself.
 
Upvote 0
Yes...it would need a "missing 1" trap
As I suggested in post #11. :)

How about this array-entered** formula...

=MIN(IF(A6:A1006-A5:A1005>1,A5:A1005+1))

**Commit this formula using CTRL+SHIFT+ENTER and not just Enter by itself.
Gives incorrect result if 1 is missing. If A5 down is ..
2,3,7 the result is 4
2,3,4 the result is 0

Also needs a missing 1 trap.

Edit: Ah, Rick I see you got this
 
Upvote 0
Yes...it would need a "missing 1" trap
Excel 2007 or later
Code:
=IFERROR(LOOKUP(2,1/(A5:A1005=(ROW(A5:A1005)-ROW(A5)+1)),A5:A1005)+1,1)
)

Pre-Excel 2007
Code:
=IF(A5<>1,1,LOOKUP(2,1/(A5:A1005=(ROW(A5:A1005)-ROW(A5)+1)),A5:A1005)+1)
EDITED TO INCLUDE THIS ALTERNATIVE:
Since we do know where the range starts, I suppose this abbreviated regular formula could be used:
Code:
=IF(A5=1,LOOKUP(2,1/(A5:A1005=(ROW(A5:A1005)-4)),A5:A1005)+1,1)

True.
I used:

=IFERROR(LOOKUP(2,1/(A5:A1005=(ROW(A5:A1005)-ROW(A5)+1)),A5:A1005)+1,1)

And it does all I need. :biggrin:

Thanks a thousand times to all of you that helped me!
 
Upvote 0

Forum statistics

Threads
1,216,095
Messages
6,128,800
Members
449,468
Latest member
AGreen17

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