How to export missing numbers into a separate worksheet

tbeynon1

New Member
Joined
Sep 16, 2015
Messages
15
Here is some code that highlights any missing for any missing numbers in column A.

Code:
'Finding missing report numbers
Dim inc As Integer
Dim inc2 As Integer
Set myrng = Range("A2:A10000")
    myrng.Interior.ColorIndex = xlNone
Set myrng = Range("A3:A10000")
    clr = 3
    inc = Range("A2").Value
    
For Each cel In myrng
        If cel.Value <> (inc + 1) Then
            cel.Interior.ColorIndex = clr
        End If
            inc = cel.Value
    If cel.Value = "" Then
        Exit Sub
    End If
Next

I was wondering if you could change it from highlighting to copying the missing numbers into a new spread sheet.
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
Here is some code that highlights any missing for any missing numbers in column A.

Rich (BB code):
'Finding missing report numbers
Dim inc As Integer
Dim inc2 As Integer
Set myrng = Range("A2:A10000")
    myrng.Interior.ColorIndex = xlNone
Set myrng = Range("A3:A10000")
    clr = 3
    inc = Range("A2").Value
    
For Each cel In myrng
        If cel.Value <> (inc + 1) Then
            cel.Interior.ColorIndex = clr
        End If
            inc = cel.Value
    If cel.Value = "" Then
        Exit Sub
    End If
Next

I was wondering if you could change it from highlighting to copying the missing numbers into a new spread sheet.
Hi tbeynon1,

Assuming you want a list generated on Sheet2 of the current workbook then you could try the following modification to your code:

Rich (BB code):
'Finding missing report numbers
Dim inc As Integer
Dim inc2 As Integer
Dim LastRow As Long

Sheets("Sheet2").Range("A1").Value = "Missing Report Numbers"
LastRow = Sheets("Sheet2").Cells(Rows.Count, "A").End(xlUp).Row + 1


Set myrng = Range("A2:A10000")
    myrng.Interior.ColorIndex = xlNone
Set myrng = Range("A3:A10000")
    clr = 3
    inc = Range("A2").Value
    
For Each cel In myrng
        If cel.Value <> (inc + 1) Then
            Sheets("Sheet2").Range("A" & LastRow).Value = cel.Value
            LastRow = LastRow + 1
        End If
            inc = cel.Value
    If cel.Value = "" Then
        Exit Sub
    End If
Next
 
Upvote 0

Forum statistics

Threads
1,221,497
Messages
6,160,151
Members
451,625
Latest member
sukhman

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