Please Note: This article is written for users of the following Microsoft Excel versions: 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365. If you are using an earlier version (Excel 2003 or earlier), this tip may not work for you. For a version of this tip written specifically for earlier versions of Excel, click here: Clearing Everything Except Formulas.

Clearing Everything Except Formulas

Written by Allen Wyatt (last updated July 27, 2023)
This tip applies to Excel 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365


4

Roni wants to clear everything in a worksheet except for cells which may contain formulas. This task can be completed either manually or through the use of a macro.

If you want to do the clearing manually, you can follow these steps:

  1. Press F5. Excel displays the Go To dialog box. (See Figure 1.)
  2. Figure 1. The Go To dialog box.

  3. Click the Special button. Excel displays the Go To Special dialog box. (See Figure 2.)
  4. Figure 2. The Go To Special dialog box.

  5. Select the Constants radio button. The four check boxes under the Formulas option then become available. (This can be a bit confusing. Why Microsoft made the Constants radio button control some check boxes under a different radio button is not immediately clear.)
  6. Make sure that all the check boxes under the Formulas radio button are selected. (They should be selected by default.)
  7. Click OK. Excel selects all the constants (cells that don't contain formulas) in the worksheet.
  8. Press the Del key.

This works great if you only need to clear out the non-formula contents of a worksheet once in a while. If you need to do it more often, then you can simply use the macro recorder to record the above steps. Or, if you prefer, you can create your own macro from scratch, such as the following one:

Sub ClearAllButFormulas()
    Dim wks As Worksheet

    'ignore errors in case there is only formulas
    On Error Resume Next
    For Each wks In Worksheets
        wks.Cells.SpecialCells(xlCellTypeConstants).ClearContents
    Next
    On Error GoTo 0
    Set wks = Nothing
End Sub

This macro is particularly useful if you need to clear out all the non-formula cells in an entire workbook. The reason is because it does the clearing on every worksheet in the entire workbook, without you needing to do the clearing manually.

You should use caution when using this macro. Make sure you really do want to clear out everything except for cells that contain formulas in the worksheet or workbook before you run this macro. It would be a shame to accidentally get rid of the contents of cells that you really needed to keep. If you are a bit squeamish about such a possibility, you might want to use the following version of the macro:

Sub ClearAllButFormulas2()
    Dim wks As Worksheet
    Dim sTemp As String
    Dim iCheck As Integer

    sTemp = "This macro deletes everything in the current "
    sTemp = sTemp & "workbook except formulas. Once done, "
    sTemp = sTemp & "it cannot be undone." & vbCrLf & vbCrLf
    sTemp = sTemp & "Are you sure you want to continue?"

    iCheck = MsgBox(sTemp, vbYesNo + vbExclamation, "Warning!")

    If iCheck = vbYes Then
        'ignore errors in case there is only formulas
        On Error Resume Next
        For Each wks In Worksheets
            wks.Cells.SpecialCells(xlCellTypeConstants).ClearContents
        Next
        On Error GoTo 0
    Else
        MsgBox "Operation cancelled."
    End If
End Sub

This version displays a message box asking if you are sure you want to do the clearing. The upshot is that you have less of a chance of messing up your workbook by accident.

Note:

If you would like to know how to use the macros described on this page (or on any other page on the ExcelTips sites), I've prepared a special page that includes helpful information. Click here to open that special page in a new browser tab.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (9097) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365. You can find a version of this tip for the older menu interface of Excel here: Clearing Everything Except Formulas.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Changing Borders for Data Series

Microsoft Graph allows you to easily add charts to a Word document without using Excel. This tip explains how you can ...

Discover More

Formatting Subtotal Rows

Excel automatically formats subtotals for you. But what if you want to change the default to something more suitable for ...

Discover More

Negating a Cell Using a Macro

There are two ways to create macros: recording them or writing them from scratch. Some things cannot be done in a macro ...

Discover More

Excel Smarts for Beginners! Featuring the friendly and trusted For Dummies style, this popular guide shows beginners how to get up and running with Excel while also helping more experienced users get comfortable with the newest features. Check out Excel 2013 For Dummies today!

More ExcelTips (ribbon)

Ensuring Rows and Columns are Empty

Before you go about deleting rows and columns helter-skelter, it is a good idea to determine if there is anything in the ...

Discover More

Closing Up Cut Rows

When you cut and paste rows using Ctrl+X and Ctrl+V, Excel leaves empty the rows where the cut information was previously ...

Discover More

Copying Subtotals

If you have added subtotals to your worksheet data, you might want to copy those subtotals somewhere else. This is easy ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] (all 7 characters, in the sequence shown) in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is 2 + 8?

2022-01-23 18:43:48

John Mann

I like this tip, and I'm keeping a copy for future use. In the past, when I've had a similar situation, I've selected all cells (except those that are protected) and deleted the content. Since I've protected all cells except those in which I actually enter date (so formulae, titles, labels, etc are protected) I can then delete all the data. This has the advantage of not deleting useful stuff which isn't a formula.


2021-05-22 10:57:41

Prithvi

Thanks very much for the advice. found it very useful!


2020-11-04 09:05:28

R Raghavendran

Thank you for great tips.


2020-09-16 06:51:20

Murray Snudge

Excellent tip - thank you. I've created a workbook for my HMRC tax return and copy the workbook for following year so want to clear previous year data but keep formula. This tip is great!


This Site

Got a version of Excel that uses the ribbon interface (Excel 2007 or later)? This site is for you! If you use an earlier version of Excel, visit our ExcelTips site focusing on the menu interface.

Newest Tips
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.