find next available number

mduntley

Board Regular
Joined
May 23, 2015
Messages
139
Office Version
  1. 365
Platform
  1. Windows
I need to find a number that is not existing. My document is huge and I want to put in a number and it will give me a new code that isn't being used

Column A is the section that the existing code is on

B2 is where I want to put in a number.

c3 is where I want to see what is the next available number I can use.
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Show us an example of what you have. I am having a hard time understanding what you have. What would be the criteria for the next available number? Are the numbers you have sequential, random? Help us to help you by being more specific and provide examples. Your current request is to vague to understand.
 
Upvote 0
[TABLE="class: grid, width: 343"]
<tbody>[TR]
[TD="align: right"]981000001[/TD]
[TD]INPUT[/TD]
[TD]NEXT AVAILABLE NUMBER NUMBER[/TD]
[/TR]
[TR]
[TD="align: right"]981000002[/TD]
[TD="align: right"]981[/TD]
[TD="align: right"]981000005[/TD]
[/TR]
[TR]
[TD="align: right"]981000003[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="align: right"]981000004[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="align: right"]981000006[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="align: right"]981000007[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="align: right"]981000008[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="align: right"]981000009[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="align: right"]981000010[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]

I have made the table. Because there is no 981000005, c2 is showing that number. If there was a 981000005, then that field will be 981000011 because we don't have that number in that table.
 
Last edited:
Upvote 0
Try this:-
Code:
[COLOR="Navy"]Sub[/COLOR] MG09Apr18
[COLOR="Navy"]Dim[/COLOR] rng [COLOR="Navy"]As[/COLOR] Range, Dn [COLOR="Navy"]As[/COLOR] Range, Temp [COLOR="Navy"]As[/COLOR] Range, c [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long[/COLOR]
[COLOR="Navy"]Set[/COLOR] rng = Range(Range("A1"), Range("A" & Rows.Count).End(xlUp))
[COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] Dn [COLOR="Navy"]In[/COLOR] rng
    [COLOR="Navy"]If[/COLOR] Val(Left(Dn.Value, 3)) = Range("B2").Value [COLOR="Navy"]Then[/COLOR]
        [COLOR="Navy"]If[/COLOR] Not Temp [COLOR="Navy"]Is[/COLOR] Nothing [COLOR="Navy"]Then[/COLOR]
            [COLOR="Navy"]If[/COLOR] Not Dn.Value = Temp + 1 [COLOR="Navy"]Then[/COLOR]
                Range("C2").Value = Temp + 1
                [COLOR="Navy"]Exit[/COLOR] For
             [COLOR="Navy"]End[/COLOR] If
        [COLOR="Navy"]End[/COLOR] If
  [COLOR="Navy"]End[/COLOR] If
[COLOR="Navy"]Set[/COLOR] Temp = Dn
[COLOR="Navy"]Next[/COLOR] Dn
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]
Regards Mick
 
Upvote 0
Is there a way to do it as a formula or does it have a VBA?
 
Upvote 0
When i try this in my original value, it comes back with the previous number that i have. When I put in 960 it comes back with 949000005. Clarification, when i put in the 3 number, i have a formula to make it end with 000001, so if i put in 960, the result will be 960000001

Try this:-
Code:
[COLOR=Navy]Sub[/COLOR] MG09Apr18
[COLOR=Navy]Dim[/COLOR] rng [COLOR=Navy]As[/COLOR] Range, Dn [COLOR=Navy]As[/COLOR] Range, Temp [COLOR=Navy]As[/COLOR] Range, c [COLOR=Navy]As[/COLOR] [COLOR=Navy]Long[/COLOR]
[COLOR=Navy]Set[/COLOR] rng = Range(Range("A1"), Range("A" & Rows.Count).End(xlUp))
[COLOR=Navy]For[/COLOR] [COLOR=Navy]Each[/COLOR] Dn [COLOR=Navy]In[/COLOR] rng
    [COLOR=Navy]If[/COLOR] Val(Left(Dn.Value, 3)) = Range("B2").Value [COLOR=Navy]Then[/COLOR]
        [COLOR=Navy]If[/COLOR] Not Temp [COLOR=Navy]Is[/COLOR] Nothing [COLOR=Navy]Then[/COLOR]
            [COLOR=Navy]If[/COLOR] Not Dn.Value = Temp + 1 [COLOR=Navy]Then[/COLOR]
                Range("C2").Value = Temp + 1
                [COLOR=Navy]Exit[/COLOR] For
             [COLOR=Navy]End[/COLOR] If
        [COLOR=Navy]End[/COLOR] If
  [COLOR=Navy]End[/COLOR] If
[COLOR=Navy]Set[/COLOR] Temp = Dn
[COLOR=Navy]Next[/COLOR] Dn
[COLOR=Navy]End[/COLOR] [COLOR=Navy]Sub[/COLOR]
Regards Mick
 
Last edited:
Upvote 0
Can you show some Real data with some possible expected results, and clarify the purpose/formula for cell "B2".
 
Upvote 0
here is an example. I cant post all of the 3420 numbers.

[TABLE="class: grid, width: 222"]
<tbody>[TR]
[TD="align: right"]949000001[/TD]
[TD]INPUT[/TD]
[TD][/TD]
[/TR]
[TR]
[TD="align: right"]949000002[/TD]
[TD]961[/TD]
[TD]960000006[/TD]
[/TR]
[TR]
[TD="align: right"]949000003[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="align: right"]949000004[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="align: right"]960000001[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="align: right"]960000002[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="align: right"]960000003[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="align: right"]960000004[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="align: right"]960000005[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="align: right"]961000001[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]


If I put in cell B2, i want the expected to be 961 I want 961000002, but it is giving me 960000006. If i put in 960 in b2, i want 960000006 but when i do it, i get 949000005
 
Last edited:
Upvote 0
Try
=INDEX((B2&"000"&TEXT(ROW($1:$999),"000"))*1,MATCH(0,COUNTIF($A$1:$A$4000,(B2&"000"&TEXT(ROW($1:$999),"000"))*1),0))

Enter with Ctrl-Shift-Enter (not just Enter)
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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