VBA & Macro Problems

Find Missing Numbers in an Excel Range with VBA

John WilsonJohn Wilson Nov 27, 2026 869 views

Question details

Find numbers missing from a specified sequence in an Excel column and list them on another worksheet.

Find Missing Numbers in an Excel Range with VBA
Product
Microsoft Excel
Device & OS
not provided
Scenario
Compare existing column values with the complete sequence from 1 through 48 using a VBA routine.
Observed behavior
The desired result is a list of absent numbers on a separate worksheet.
Before you start

Open the workbook in desktop Excel and identify the source sheet and column. The example reads Sheet1!A1:A1000 and clears column A on a sheet named MissingNumbers before writing results, so check those locations first.

Solution 1Recommended

Use a VBA macro to list missing numbers on another sheet

Run this macro when your source numbers are in one column and you want a separate list of values missing from 1 through 48.

The macro checks each number from 1 to 48 against Sheet1!A1:A1000. It creates a MissingNumbers sheet if needed, or clears column A on the existing sheet before writing the results.

1
Open the VBA editor

In desktop Excel, open the workbook, then choose Developer > Visual Basic. If the Developer tab is hidden, enable it through File > Options > Customize Ribbon.

2
Insert the macro

In the VBA editor, select the workbook and choose Insert > Module. Paste this code into the module: Sub FindMissingNumbers() Dim sourceSheet As Worksheet Dim outputSheet As Worksheet Dim n As Long Dim outputRow As Long Set sourceSheet = ThisWorkbook.Worksheets("Sheet1") On Error Resume Next Set outputSheet = ThisWorkbook.Worksheets("MissingNumbers") On Error GoTo 0 If outputSheet Is Nothing Then Set outputSheet = ThisWorkbook.Worksheets.Add(After:=ThisWorkbook.Worksheets(ThisWorkbook.Worksheets.Count)) outputSheet.Name = "MissingNumbers" End If outputSheet.Columns("A").ClearContents outputSheet.Range("A1").Value = "Missing numbers" outputRow = 2 For n = 1 To 48 If Application.WorksheetFunction.CountIf(sourceSheet.Range("A1:A1000"), n) = 0 Then outputSheet.Cells(outputRow, 1).Value = n outputRow = outputRow + 1 End If Next n End Sub

3
Adjust the source and sequence

In the pasted code, replace "Sheet1" and "A1:A1000" with your source sheet name and range. Change the bounds in For n = 1 To 48 if you need a different sequence.

4
Run and review the results

In Excel, choose Developer > Macros, select FindMissingNumbers, and click Run. Open the MissingNumbers sheet to review the list in column A; if no values are missing, only the header appears.

5
Save the macro

Choose File > Save As and select Excel Macro-Enabled Workbook (*.xlsm) if you want to keep the VBA procedure in the workbook.

Use a VBA macro to list missing numbers on another sheet
Check the output column: Running the macro clears all existing contents in column A of MissingNumbers. Use a different output sheet name in the code if that column contains data you need.
Find missing numbers without a macro

Find missing sequence values in WPS Spreadsheet

Use a candidate list, COUNTIF, and a filter in WPS Spreadsheet to identify missing values on a separate sheet without running Excel VBA.

  1. 1. Open the workbook: Open your workbook in WPS Spreadsheet and check that the source values are in Sheet1!A1:A1000, or note the actual sheet and range.
  2. 2. Create the candidate list: Add a worksheet using the plus button beside the sheet tabs. Enter Number in A1 and Status in B1. Enter 1 in A2 and =A2+1 in A3, then drag A3's fill handle down to A49 to create the sequence through 48.
  3. 3. Check each number: In B2, enter =IF(COUNTIF(Sheet1!$A$1:$A$1000,A2)=0,"Missing","Present"). Adjust the sheet name and range if necessary, then drag the fill handle down to B49.
  4. 4. Filter the missing values: Select A1:B49 and choose Data > Filter. Open the filter in the Status header and select Missing to display the absent numbers in column A.
Identify missing numbers with a COUNTIF formula and filterOpen and save Microsoft Excel XLSX workbooksUse a familiar spreadsheet interfaceAdjust the candidate list for other number ranges
microsoft office alternative - wps office

Frequently Asked Questions

How do I change the range of numbers being checked?

In the VBA module, change the bounds in For n = 1 To 48. For example, use For n = 10 To 100 to check integers from 10 through 100.

What if my source values are on a different worksheet?

Replace "Sheet1" in ThisWorkbook.Worksheets("Sheet1") with the actual worksheet name, and update the range in sourceSheet.Range("A1:A1000") if needed.

Will duplicate values affect the missing-number list?

No. COUNTIF checks whether each candidate appears at least once, so duplicates do not create extra entries in the missing-number list.

Can I run this VBA macro in Excel for the web?

Excel for the web cannot run VBA macros. Open the workbook in desktop Excel and use Developer > Macros to run the procedure.