Excel VBA Find Numbers Only: Code, Search Tips, and Fixes

VBA & macros · Updated November 3, 2026

Excel VBA Find Numbers Only: Code, Search Tips, and Fixes

Yes. To find cells that contain real numeric values—not numbers stored as text—loop through the range and check each cell’s value. The VBA example below prints the address and value of every numeric cell in A1:D100.

VBA code to find numeric cells

In Excel for Microsoft 365 on Windows, press Alt+F11 to open the Visual Basic Editor, choose Insert > Module, and paste this macro. It assumes the code is stored in the same workbook as the data and that the worksheet is named Sheet1.

Sub ListNumericCells()
    Dim ws As Worksheet
    Dim searchRange As Range
    Dim cell As Range
    Dim v As Variant

    ' Set the worksheet and range to search.
    Set ws = ThisWorkbook.Worksheets("Sheet1")
    Set searchRange = ws.Range("A1:D100")

    ' Print each cell containing a numeric value.
    For Each cell In searchRange.Cells
        v = cell.Value2
        If Not IsError(v) Then
            If Not IsEmpty(v) Then
                If VarType(v) <> vbString And VarType(v) <> vbBoolean Then
                    If IsNumeric(v) Then
                        Debug.Print cell.Address(False, False), v
                    End If
                End If
            End If
        End If
    Next cell
End Sub

Before running a macro, save a copy of the workbook: VBA changes cannot be undone with Ctrl+Z. To run this one, click inside the procedure in the editor and press F5. Open the Immediate window with Ctrl+G to see the results. On a Mac, use Option+F11 to open the VBA editor on many keyboards; the exact shortcut can depend on the keyboard and function-key settings. Excel for the web cannot run VBA macros.

What the code counts as a number

The macro reads each cell’s Value2 property, which returns the cell’s underlying value rather than its displayed formatting. It skips errors, empty cells, text, and Boolean values, then prints cells for which IsNumeric is true. That distinction matters because IsNumeric by itself can return true for text such as “123”. The additional type check excludes text values, so a number stored as text is not reported as a numeric cell.

Numeric constants and formula results are both included. For example, a cell containing 25 and a cell with a formula that evaluates to 25 both have numeric values. A formula that returns the text “25” is excluded. The macro does not change the worksheet; it only writes addresses and values to the Immediate window.

Excel stores dates as serial numbers. Because the code reads Value2, a date is treated as numeric even when its cell formatting displays a calendar date. If you need to exclude dates, you need an additional rule based on the cell’s number format or the role of that column. Formatting alone is not a fully reliable way to identify the intended meaning of every value.

Two meanings of “find only numbers”

The question can mean either “find every cell containing a number” or “find a particular number, but do not match text that looks like that number.” The loop above addresses the first task. It scans every cell in the chosen range and reports numeric values, without needing to know what number to look for in advance.

For the second task, Excel’s Find method searches for matching content, but it is not a type filter. Searching for 25 may not be enough to distinguish a numeric 25 from text that appears as 25 in a cell. If the distinction is essential, inspect the cell value and its type in VBA, or use the loop approach to filter the range before comparing values. Also decide whether you mean an exact match or a partial match: searching for 25 can otherwise raise questions about values such as 250 or 1,250.

Change the range and return the results elsewhere

Replace A1:D100 with the range you want to inspect, such as B2:B500. Replace Sheet1 with the worksheet’s tab name, keeping the name inside quotation marks. If the sheet name contains spaces, the same syntax works—for example, Worksheets(“Quarter 1”). The worksheet must belong to the workbook referred to by ThisWorkbook, which means the workbook containing the macro.

Debug.Print is convenient for a quick inspection, but it does not create a report on the sheet. You can adapt the macro to write each address and value into a separate results column, or to highlight matching cells. Before making either change, decide whether the macro should clear old results or preserve them; otherwise, repeated runs can leave stale output or overwrite existing data. If the macro is stored in a different workbook, identify the workbook containing the data explicitly rather than assuming ThisWorkbook refers to it.

  • To search one column, set searchRange to a single-column range, such as B2:B500.
  • To search a whole worksheet, use a defined used range rather than looping through every possible Excel row and column, which can be unnecessarily slow.
  • To find negative values or values above a threshold, keep the numeric type check and add a comparison such as v < 0 or v > 100 inside the numeric branch.

Find versus a VBA loop

Range.Find is useful when you know the value or text you want and need to locate a matching cell quickly. It can search by values or formulas and supports options such as whole-cell matching. However, Excel retains some Find settings between searches, including settings used in the Find dialog, so reliable VBA should specify the relevant arguments rather than depend on whatever a user selected previously.

A loop is usually clearer when the requirement is about cell type: inspect each value, decide whether it is numeric, and then take an action. The trade-off is that a loop checks cells one at a time, so an unnecessarily large range may take longer. Keep the range focused. For very large data sets, consider whether Excel’s filtering or built-in selection tools can do the job without a macro.

When SpecialCells is a better fit

Excel’s SpecialCells method can select cells by category instead of testing each cell yourself. For example, SpecialCells with xlCellTypeConstants and xlNumbers targets numeric constants, while xlCellTypeFormulas and xlNumbers targets formula cells whose results are numeric. This is useful when you want to select or format those categories directly, but constants and formulas require separate calls if you need both.

SpecialCells can raise an error when there are no matching cells, so code using it should handle that case. It also works with Excel’s cell categories, which may not match every custom definition of “number.” If you need to exclude date serials, treat numeric text differently, or apply a business rule, a value-by-value loop gives you more control.

Common problems and checks

  • Numbers stored as text: A green triangle, left alignment, or an import warning may indicate text, but visual clues are not definitive. The macro excludes text even if it looks like a number. Convert the data only if it is appropriate to treat it as numeric.
  • Dates included: Excel represents dates numerically, so the example reports them. Decide how your workbook identifies dates before adding an exclusion rule.
  • Formula results: A formula returning a number is included; one returning text or an error is not. The code skips error values safely.
  • No results visible: The output goes to the Visual Basic Editor’s Immediate window, not a worksheet cell or message box. Open that window with Ctrl+G in the Windows editor.
  • Wrong worksheet or workbook: Confirm the tab name and whether the macro is stored in the workbook you intend to search. A misspelled sheet name causes a runtime error.
  • Macro blocked: Save macro-enabled work as an .xlsm file and enable macros only for files you trust. Do not enable macros from an unexpected attachment just to run a search.

How to run it safely

Use a copy of the workbook first, especially if you plan to modify the example to select, color, delete, or move cells. VBA actions are not reversed by Ctrl+Z. Review the range and worksheet references before running, and test the macro on a small sample where you already know which cells should qualify. If the workbook contains sensitive or business-critical data, keep an untouched backup.

The example only reads cells and prints output, but any later customization can change that. For instance, adding an assignment to a cell’s Interior.Color property would alter formatting. A macro that deletes cells or overwrites a results area has more substantial effects, so make those changes explicit and confirm the target range before execution.

Frequently Asked Questions

Can Excel VBA find every cell that contains a number?
Yes. Loop through the target range, check each cell’s value, and report the cells that qualify. The example checks actual numeric values and includes formulas whose results are numbers.

Does IsNumeric identify cells that are numeric, not text?
Not on its own. A string containing numeric characters can pass IsNumeric. Check the value’s type as well, as the example does, to exclude numbers stored as text.

Can I use Find to search for a specific number?
Yes, but Find matches content; it does not by itself guarantee that a matching cell is stored as a number. For strict type checking, inspect candidate cells with VBA after locating them or use a loop.

Will this code include dates and formula results?
It includes formula results that are numeric. It also includes dates because Excel stores date values as serial numbers. Formula results that are text or errors are excluded.

Can I run VBA in Excel for the web?
No. Excel for the web does not run VBA macros. Open the workbook in the desktop Excel app to use this code; Excel for Mac also supports VBA, though editor shortcuts can differ.

Related

Try it: the Column Letter to Number: aA is 27, XFD is 16,384. Converts both ways.

More in VBA & macros

Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources

Spotted an error in this guide? Let us know.