PDA

View Full Version : Check whether numbers are sequential?



doctortt
03-12-2014, 05:51 AM
Hi, can someone please assist? Column A contains the project number, and the number begins with AB210001, AB210002, so on. I'd like to write some codes in VBA to check whether the project numbers in column A are sequential. The system that I pull the report from sometimes misses some projects.

ashleyuk1984
03-12-2014, 06:20 AM
This is my little take on your problem.


Sub AshCount()
Dim StartRow As Integer
Dim EndRow As Integer
Dim CompareNum As String
Dim x As Integer

StartRow = 1
EndRow = Range("A9999").End(xlUp).Row

CompareNum = Right(Range("A1").Value, 6)

For x = StartRow To EndRow
If Right(Range("A" & x).Value, 6) <> CompareNum Then
MsgBox "Missing Reference between rows " & x - 1 & " and " & x
Range("A" & x - 1).Select
Exit Sub
End If
CompareNum = CompareNum + 1
Next x

End Sub