find missing numbers

inosent

Board Regular
Joined
Mar 19, 2007
Messages
131
i have two columns of numbers that represent file numbers

one column is (eg)


2
3
5
6
7
9

the other is

3
6
7

the second column is 'missing'

2
5
9

how do i look at the long column, compare it to the short column, and produce the list of missing numbers?
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
inosent,


Sample raw data before the macro:


Excel Workbook
ABC
123
236
357
46
57
69
7
Sheet1





After the macro:


Excel Workbook
ABC
1232
2365
3579
46
57
69
7
Sheet1





Please TEST this FIRST in a COPY of your workbook (always make a backup copy before trying new code, you never know what you might lose).


1. Copy the below code, by highlighting the code and pressing the keys CTRL + C
2. Open your workbook
3. Press the keys ALT + F11 to open the Visual Basic Editor
4. Press the keys ALT + I to activate the Insert menu
5. Press M to insert a Standard Module
6. Where the cursor is flashing, paste the code by pressing the keys CTRL + V
7. Press the keys ALT + Q to exit the Editor, and return to Excel
8. To run the macro from Excel, open the workbook, and press ALT + F8 to display the Run Macro Dialog. Double Click the macro's name to Run it.


Code:
Option Explicit
Sub FindMissing()
' hiker95, 06/23/2011
' http://www.mrexcel.com/forum/showthread.php?t=559503
Dim c As Range, FR As Long, NR As Long
Columns(3).ClearContents
NR = 0
For Each c In Range("A1", Range("A" & Rows.Count).End(xlUp))
  FR = 0
  On Error Resume Next
  FR = Application.Match(c, Columns(2), 0)
  On Error GoTo 0
  If FR = 0 Then
    NR = NR + 1
    Cells(NR, 3) = c
  End If
Next c
End Sub


Then run the FindMissing macro.
 
Upvote 0
inosent,

You are very welcome.

Glad I could help.

Thanks for the feedback.

Come back anytime.
 
Upvote 0

Forum statistics

Threads
1,224,518
Messages
6,179,258
Members
452,901
Latest member
LisaGo

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