View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Greg Wilson[_4_] Greg Wilson[_4_] is offline
external usenet poster
 
Posts: 218
Default Non-consecutive numbers in Macro

This assumes that the invoice numbers start in Cell A2 of
Sheet2 (header in A1?) and that the missing invoice
numbers are to be transferred to Sheet2 starting in the
first availble cell in Column A:

Sub FindMissingInvoiceNums()
Dim Rng As Range
Dim C1 As Range, C2 As Range
Dim x As Long
On Error Resume Next
With Sheets("Sheet1")
x = .Cells(Rows.Count, 1).End(xlUp).Row
Set Rng = .Range(.Cells(2, 1), .Cells(x, 1))
End With
With Sheets("Sheet2")
x = .Cells(Rows.Count, 1).End(xlUp).Row
Set C2 = .Cells(x, 1)(2)
End With
x = 0
For Each C1 In Rng
If C1.Row Rng(1).Row Then
If C1 - C1(0) 1 Then
For x = 1 To C1 - C1(0) - 1
C2 = C1(0) + x
Set C2 = C2(2)
Next
x = 0
End If
End If
Next
On Error GoTo 0
End Sub

Regards,
Greg


-----Original Message-----
After not wanting to, it looks like I do need to create a
macro. How would I do the following to make sure that it
captures a range of missing numbers (1006-1008 below)? I
need to find all gaps in the Invoice # list and flag the
numbers to a new worksheet(#2), preferably all listed in
Column A without gaps.

Worksheet #1 Worksheet #2
Invoice# Customer Invoice#
1001 Acme 1003
1002 Davis 1006
1004 Shopstar 1007
1005 Walker 1008
1009 Trains

Thanks for any help.


.