Excel VBA: How to Change Cell Formats to General

VBA & macros · Updated November 19, 2026

To change a cell’s number format to General with VBA, assign General to its NumberFormat property: Worksheets("Sheet1").Range("A1").NumberFormat = "General". This changes how Excel displays the cell’s value; it does not convert the value or restore a previous custom format.

The basic VBA method

The NumberFormat property controls a range’s number format. Set it to the string General to apply Excel’s default number display. The example below targets cell A1 on a worksheet named Sheet1 in the workbook containing the macro:

Sub SetA1ToGeneral()
    Dim ws As Worksheet

    ' Refer to the worksheet in the workbook that contains this macro.
    Set ws = ThisWorkbook.Worksheets("Sheet1")
    ws.Range("A1").NumberFormat = "General"
End Sub

Change the sheet name and range to match your workbook. The worksheet name in the code must match the sheet tab name exactly. If that sheet does not exist, VBA raises an error rather than applying the format elsewhere.

Before running a macro that changes formatting, save a copy of the workbook. VBA actions cannot be undone with Ctrl+Z, so a backup is the straightforward way to recover if the macro affects the wrong cells.

Apply General to a range, column, or selection

The same property works on any Excel Range, not only one cell. For a known block, specify its address explicitly. With a worksheet named Sheet1 and the cells A2 through D100 as the intended target, use:

Sub SetBlockToGeneral()
    Dim ws As Worksheet
    Dim target As Range

    Set ws = ThisWorkbook.Worksheets("Sheet1")
    Set target = ws.Range("A2:D100")
    target.NumberFormat = "General"
End Sub

For an entire column, replace the range assignment with Set target = ws.Columns("B"). Applying a format to a whole column is convenient when future entries should also use General, but it affects every cell in that column, including cells outside the visible data. Choose a bounded range when only existing records should change.

You can also format the current selection, which is useful when a person selects the cells before running a macro. This version checks that the active selection is a range:

Sub SetSelectionToGeneral()
    Dim target As Range

    ' Exit if the current selection is not a worksheet range.
    If TypeName(Selection) <> "Range" Then Exit Sub
    Set target = Selection
    target.NumberFormat = "General"
End Sub

Selection-based macros are less predictable in automated workflows: the active sheet and selected cells depend on what the user did immediately beforehand. For a repeatable process, refer to the worksheet and range by name instead.

What General means in Excel

General is Excel’s default number format. It lets Excel choose a display suitable for the underlying value rather than forcing a particular pattern such as currency, a fixed number of decimal places, or a date. A number might appear without unnecessary trailing zeroes, while a sufficiently large or small number may appear in scientific notation. The precise display depends on the value and the available cell width.

Formatting and contents are separate. Changing NumberFormat does not replace a formula, recalculate a formula into a constant, or turn text into a number. If A1 contains the formula =SUM(B1:B5), setting A1 to General leaves that formula in place and changes its number display. Likewise, a text entry remains text.

This distinction matters because General is not a command to “reset” every aspect of a cell. It changes the number format, but does not clear the font, fill, borders, alignment, validation, comments, or other cell settings. To remove all formatting, a different operation is needed—and that would do more than set the number format to General.

Dates, decimals, and leading zeroes

Dates are a common reason a cell seems to change dramatically after a macro. In a standard Excel workbook, dates are represented internally as serial numbers, with times represented as fractions of a day. If a cell displays a calendar date because it has a date format, changing it to General can show the underlying serial value instead. The date has not been erased; only its display format changed. Applying a date format again can make the serial display as a date.

Custom formats can also add characters that are not part of the stored value. For example, a five-digit display such as 00123 may come from the custom number format 00000 applied to the numeric value 123. General normally displays that numeric value as 123, so the leading zeroes disappear from view. If the cell instead contains the text string 00123, General does not remove those characters because they are part of the text.

Similarly, General does not guarantee that a number will display with a fixed number of decimal places. If a report requires two decimal places or a consistent date presentation, retain or apply a suitable number format rather than relying on General. Use General when the goal is to let Excel show the value without a specialized number-format pattern.

NumberFormat and NumberFormatLocal

For ordinary VBA automation, NumberFormat is usually the appropriate property. Its format codes use Excel’s language-independent format syntax, so "General" is suitable even when a user’s regional settings differ. NumberFormatLocal works with format codes as displayed in the user’s local language and conventions. That can be useful when a macro specifically handles localized format strings, but it can make code less portable across computers.

Do not confuse the property with a method called “Format.” In this case, the relevant syntax is to assign the format to the range’s NumberFormat property. For example, after declaring a worksheet variable named ws, ws.Range("C2:C20").NumberFormat = "General" applies the setting to every cell in that range.

In Excel for Microsoft 365 on Windows, the equivalent manual action is to select the cells, go to Home > Number Format in the Number group, and choose General. The ribbon label may be displayed as a drop-down control. Excel for Mac has a similar Home tab number-format control, although the ribbon layout can vary. Excel for the web also offers number-format choices on its Home tab, but it does not run VBA macros; use desktop Excel to execute this code.

Common problems and how to avoid them

  • The wrong cells change: A macro using Selection acts on the current selection. Prefer a fully qualified reference such as ThisWorkbook.Worksheets("Sheet1").Range("A1:A20") when the target is known.
  • The date appears as a number: That is expected when the cell’s underlying value is a date serial and the date format is replaced by General. Reapply a date format if the intended display is a calendar date.
  • Leading zeroes disappear: Check whether the cell contains a number displayed with a custom format or text that includes zeroes. General reveals the numeric value without the custom padding; it does not strip characters from text.
  • The display still looks unusual: General does not force a fixed decimal count or prevent scientific notation. Also check whether the column is too narrow, or whether the value is stored as text.
  • The appearance does not seem to change: The cell may already be General, or a conditional formatting rule may affect its appearance. Setting NumberFormat does not delete conditional formatting rules; inspect the rules if a conditional format is responsible for the displayed result.
  • The macro reports a missing worksheet: Verify the tab name and whether the code should refer to ThisWorkbook (the workbook containing the macro) or another workbook. Qualifying the worksheet avoids accidentally formatting a similarly named active sheet in a different workbook.

One important limitation is that General does not recover the cell’s original format. If a cell was Currency before the macro ran, assigning General discards that current number-format choice. Excel does not keep a simple “previous number format” history that this assignment can automatically restore. If preserving the original appearance matters, record the existing format first or work from a saved copy.

Choosing a safe scope for the macro

The best target depends on why you are changing the format. A one-cell correction should name one cell. A data-import routine might format only the imported block. A template intended for future entries might format a full input column. Consider the consequences before using UsedRange: it refers to the worksheet’s used range, which can include cells that were formatted in the past even if they look empty now. It may therefore cover more cells than the visible data records.

For repeatable routines, qualify every range with a worksheet variable and use explicit addresses or a range calculated from known data boundaries. Avoid relying on whichever workbook or worksheet happens to be active. If a macro is part of a larger import or cleanup process, decide whether headers, formulas, blank cells, and totals belong in the target before applying the format.

For a small, one-time task, the ribbon is often simpler than writing a macro. VBA is more useful when the same formatting step must be repeated, applied to a known range as part of a larger procedure, or run consistently across multiple sheets. A macro-enabled workbook must be saved in a format that supports macros, such as Excel Macro-Enabled Workbook (.xlsm), if the VBA code needs to remain available in that file.

Frequently Asked Questions

What is the VBA code to make a cell General?
Use Range("A1").NumberFormat = "General", with the range qualified by the correct worksheet when possible. For example, Worksheets("Sheet1").Range("A1").NumberFormat = "General".

Does changing a cell to General convert text to a number?
No. The setting changes the number format, not the stored data type. Text that looks like a number remains text until it is converted separately.

Why does my date turn into a number after I set General?
Excel stores dates as serial values and date formatting displays those values as calendar dates. General exposes the serial-number display; it does not delete the date value.

Can I set an entire column to General?
Yes. Use a reference such as ws.Columns("B").NumberFormat = "General" after setting ws to the intended worksheet. Remember that this affects the whole column, not just filled rows.

Can I undo a VBA format change with Ctrl+Z?
No. Running a VBA macro clears Excel’s ordinary undo history, so Ctrl+Z cannot reverse the macro’s formatting change. Save a copy first if you may need to restore the workbook.

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.