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:

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
Using this example
Code:
Ex:
-| A | B |
1| 1 | (Function to return "3")
2| 2 |
3| 4 |
4| 7 |
5| 8 |
6| 9 |
7|   |
8|
9|

This regular formula returns the first missing number in the sequence
Code:
B1: =INDEX(A:A,MATCH(1,INDEX(--((A2:A20-A1:A19)<>1),0),0))+1
In that example, that formula returns: 3

Is that something you can work with?
 
Upvote 0
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.

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.
Is the range of numbers always from 1 to N?

Will 1 always be present?
 
Upvote 0
Is the range of numbers always from 1 to N?

Will 1 always be present?

Nope, 1 might not be present and the highest number is unknown (but never seen and higher than 1000). If 1 is not present then 1 should be next missing number.
 
Upvote 0
Oh! I also forgot the numbers starts from A5 and down not from A1 as my example. I have some text and headers A1 to D4
 
Upvote 0
Oh! I also forgot the numbers starts from A5 and down not from A1 as my example. I have some text and headers A1 to D4
Ok, does that mean the sequence starts from 1 although 1 may not be present?

We need to establish a starting point for the missing number(s)!
 
Upvote 0
This regular formula returns the first missing number in the sequence
Code:
B1: =INDEX(A:A,MATCH(1,INDEX(--((A2:A20-A1:A19)<>1),0),0))+1
In that example, that formula returns: 3

Is that something you can work with?
This seem just to return the lowest value +1. = value 2 if my lowest value is 1.
 
Last edited:
Upvote 0
Ok, does that mean the sequence starts from 1 although 1 may not be present?
Yes

We need to establish a starting point for the missing number(s)!
Hmm, to do some sort of range we can check for next missing number in the range of 1 to 10000.
 
Upvote 0
Ok, does that mean the sequence starts from 1 although 1 may not be present?
Yes

We need to establish a starting point for the missing number(s)!
Hmm, to do some sort of range we can check for next missing number in the range of 1 to 10000.

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?
 
Upvote 0
Ok, does that mean the sequence starts from 1 although 1 may not be present?
Yes

We need to establish a starting point for the missing number(s)!
Hmm, to do some sort of range we can check for next missing number in the range of 1 to 10000.
Try this...

Book1
AB
213
32_
44_
57_
68_
79_
Sheet1

Create this defined name formula:

Name: Nums
Refers to: =ROW(INDIRECT("1:10000"))

Then, enter this array formula** in B2:

=SMALL(IF(ISNA(MATCH(Nums,A$2:A$7,0)),Nums),ROWS(B$2:B2))

** array formulas need to be entered using the key
combination of CTRL,SHIFT,ENTER (not just ENTER).
Hold down both the CTRL key and the SHIFT key
then hit ENTER.
 
Upvote 0

Forum statistics

Threads
1,215,465
Messages
6,124,975
Members
449,200
Latest member
Jamil ahmed

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