View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Doug Glancy Doug Glancy is offline
external usenet poster
 
Posts: 770
Default Non-consecutive numbers in Macro

Ramona,

This works with the active sheet and puts the results in "Sheet 2". It
assumes the invoice numbers are in column A. It's slow, so if you've got
more than a few thousand, go pour a cup of coffee:

Sub test()

Dim last_row As Long
Dim invoice_range As Range
Dim all_invoices() As String
Dim start_num As Long, last_num As Long
Dim i As Long
Dim print_row As Long

last_row = ActiveSheet.Range("A" & Rows.Count).End(xlUp).Row
Set invoice_range = ActiveSheet.Range("A1:A" & last_row)
start_num = ActiveSheet.Range("A2")
last_num = ActiveSheet.Range("A" & last_row).Value
ReDim all_invoices(start_num To last_num)

For i = start_num To last_num
If Application.WorksheetFunction.CountIf(invoice_rang e, i) = 0 Then
all_invoices(i) = "missing"
End If
Next i

Worksheets("Sheet2").Cells.Clear
Worksheets("Sheet2").Range("A1").Value = "Missing Invoices"
print_row = 2

For i = start_num To last_num
If all_invoices(i) = "missing" Then
Worksheets("Sheet2").Range("A" & print_row) = i
print_row = print_row + 1
End If
Next i

End Sub
hth,

Doug Glancy

"Ramona" wrote in 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.