Need to find sequential serial numbers and group them counting # of #

csharpe3

New Member
Joined
Oct 28, 2013
Messages
2
I have serial numbers on the same product that is numbered sequentially. For some reason we have sold individual serial numbers and they are no longer consecutive. I need to be able to find sequential numbers, Label them as consecutive and display how many consecutive numbers are in a group and what number that unit is of the group.

The goal is to be able to find a customer the smallest block of consecutive numbers that meet their needs without breaking larger groups of consecutive numbers.

Columns = Description = Current formula
Number = Serial numbers sorted smallest to largest = No formula
Group = Is the serial part of a sequential group or not sequential. =
Code:
=IF(A1=A2-1,"Consecutive","Not")
1 = What is the sequence of the number in the group =
Code:
=IF(B2="Consecutive",1+C1,1)
Of Group = "This is what I need help with. I want to display the number of this serial number in the total of the consecutive numbers. =
Code:
Need help

Sample
Number
Group1Singleof Group
2105590001Not1Group1 of 5
2105590002Consecutive2Group2 of 5
2105590003Consecutive3Group3 of 5
2105590004Consecutive4Group4 of 5
2105590005Consecutive5Group5 of 5
2105590007Not1Group1 of 3
2105590008Consecutive2Group2 of 3
2105590009Consecutive3Group3 of 3
2105590011Not1single1 of 1
2105590013Not1Group1 of 3
2105590014Consecutive2Group2 of 3
2105590015Consecutive3Group3 of 3
2105590017Not1Group1 of 2
2105590018Consecutive2Group2 of 2
2105590020Not1single1 of 1
2105590022Not1single1 of 1
2105590024Not1single1 of 1
2105590026Not1Group1 of 2
2105590027Consecutive2Group2 of 2
2105590029Not1single1 of 1
2105590031Not1single1 of 1
2105590033Not1Group1 of 18
2105590034Consecutive2Group2 of 18
2105590035Consecutive3Group3 of 18
2105590036Consecutive4Group4 of 18
2105590037Consecutive5Group5 of 18

<colgroup><col><col><col span="3"></colgroup><tbody>
</tbody>
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
If you're happy to do it with code , try this:-
Code:
[COLOR="Navy"]Sub[/COLOR] MG28Oct19
[COLOR="Navy"]Dim[/COLOR] Rng     [COLOR="Navy"]As[/COLOR] Range
[COLOR="Navy"]Dim[/COLOR] Dn      [COLOR="Navy"]As[/COLOR] Range
[COLOR="Navy"]Dim[/COLOR] nRng    [COLOR="Navy"]As[/COLOR] Range
[COLOR="Navy"]Dim[/COLOR] r       [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long[/COLOR]
[COLOR="Navy"]Set[/COLOR] Rng = Range(Range("A2"), Range("A" & Rows.Count).End(xlUp))
[COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] Dn [COLOR="Navy"]In[/COLOR] Rng
    [COLOR="Navy"]If[/COLOR] nRng [COLOR="Navy"]Is[/COLOR] Nothing [COLOR="Navy"]Then[/COLOR]
        [COLOR="Navy"]Set[/COLOR] nRng = Dn
    [COLOR="Navy"]Else[/COLOR]
        [COLOR="Navy"]Set[/COLOR] nRng = Union(nRng, Dn)
    [COLOR="Navy"]End[/COLOR] If
    
    [COLOR="Navy"]If[/COLOR] Not Dn.Offset(1) = Dn + 1 [COLOR="Navy"]Then[/COLOR]
        [COLOR="Navy"]If[/COLOR] Not nRng [COLOR="Navy"]Is[/COLOR] Nothing [COLOR="Navy"]Then[/COLOR]
            [COLOR="Navy"]For[/COLOR] r = 1 To nRng.Count
                nRng(r).Offset(, 4) = r & " of " & nRng.Count
            [COLOR="Navy"]Next[/COLOR] r
         [COLOR="Navy"]End[/COLOR] If
            [COLOR="Navy"]Set[/COLOR] nRng = Nothing
    [COLOR="Navy"]End[/COLOR] If


[COLOR="Navy"]Next[/COLOR] Dn
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]
Regards Mick
 
Upvote 0
Re: Need to find sequential serial numbers and group them counting # of # - solution

Mick,

Thank you.

Others, If you need to use this code, Select the column you want the data to appear and run the macro. Works really nice.


If you're happy to do it with code , try this:-
Code:
[COLOR=Navy]Sub[/COLOR] MG28Oct19
[COLOR=Navy]Dim[/COLOR] Rng     [COLOR=Navy]As[/COLOR] Range
[COLOR=Navy]Dim[/COLOR] Dn      [COLOR=Navy]As[/COLOR] Range
[COLOR=Navy]Dim[/COLOR] nRng    [COLOR=Navy]As[/COLOR] Range
[COLOR=Navy]Dim[/COLOR] r       [COLOR=Navy]As[/COLOR] [COLOR=Navy]Long[/COLOR]
[COLOR=Navy]Set[/COLOR] Rng = Range(Range("A2"), Range("A" & Rows.Count).End(xlUp))
[COLOR=Navy]For[/COLOR] [COLOR=Navy]Each[/COLOR] Dn [COLOR=Navy]In[/COLOR] Rng
    [COLOR=Navy]If[/COLOR] nRng [COLOR=Navy]Is[/COLOR] Nothing [COLOR=Navy]Then[/COLOR]
        [COLOR=Navy]Set[/COLOR] nRng = Dn
    [COLOR=Navy]Else[/COLOR]
        [COLOR=Navy]Set[/COLOR] nRng = Union(nRng, Dn)
    [COLOR=Navy]End[/COLOR] If
    
    [COLOR=Navy]If[/COLOR] Not Dn.Offset(1) = Dn + 1 [COLOR=Navy]Then[/COLOR]
        [COLOR=Navy]If[/COLOR] Not nRng [COLOR=Navy]Is[/COLOR] Nothing [COLOR=Navy]Then[/COLOR]
            [COLOR=Navy]For[/COLOR] r = 1 To nRng.Count
                nRng(r).Offset(, 4) = r & " of " & nRng.Count
            [COLOR=Navy]Next[/COLOR] r
         [COLOR=Navy]End[/COLOR] If
            [COLOR=Navy]Set[/COLOR] nRng = Nothing
    [COLOR=Navy]End[/COLOR] If


[COLOR=Navy]Next[/COLOR] Dn
[COLOR=Navy]End[/COLOR] [COLOR=Navy]Sub[/COLOR]
Regards Mick
 
Upvote 0
Re: Need to find sequential serial numbers and group them counting # of # - solution

You're welcome
Regrds Mick
 
Upvote 0

Forum statistics

Threads
1,215,603
Messages
6,125,782
Members
449,259
Latest member
rehanahmadawan

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