Hi all.
Could anyone help with showing missing numbers in a sequence
I have been using the code below which works well.
The example below shows just 5 & 7 missing, which is correct
If the number does not start at 1 as below, it shows all numbers from 1. Then shows the number that is really missing, which is 13
Is there a way to just show the missing numbers from the first number entered
Thanks for looking,
Graham
Could anyone help with showing missing numbers in a sequence
I have been using the code below which works well.
VBA Code:
Sub Missing_Numbers_in_Sequence()
' This loops through Column A and checks for missing numbers in a sequence.
' Then shows the missing numbers in column C
Dim iLoop As Long, iLoop2 As Long
Dim Last_Row As Long
Dim Old_Number As Long, New_Number As Long
Last_Row = Range("A5000").End(xlUp).Row
Old_Number = Val(Right(ActiveSheet.Range("A1").Value, 5))
For iLoop = 1 To Last_Row
New_Number = Val(Right(Worksheets(1).Range("A" & iLoop).Value, 5))
For iLoop2 = Old_Number To (New_Number - 2)
ActiveSheet.Range("C" & Range("C5000").End(xlUp).Row + 1).Value = _
"" & iLoop2 + 1 & ""
Next iLoop2
Old_Number = New_Number
Next iLoop
End Sub
The example below shows just 5 & 7 missing, which is correct
A | B | C |
Number | Description | Missing Numbers |
1 | Chair | 5 |
2 | Speaker | 7 |
3 | Phone | |
4 | TV | |
6 | Table | |
8 | Soundbar |
If the number does not start at 1 as below, it shows all numbers from 1. Then shows the number that is really missing, which is 13
A | B | C |
Number | Description | Missing Numbers |
8 | Chair | 1 |
9 | Speaker | 2 |
10 | Phone | 3 |
11 | TV | 4 |
12 | Table | 5 |
14 | Phone | 6 |
7 | ||
13 |
Is there a way to just show the missing numbers from the first number entered
Thanks for looking,
Graham