Please Note: This article is written for users of the following Microsoft Excel versions: 2007, 2010, and 2013. 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

by Allen Wyatt
(last updated January 17, 2015)

22

Roni wants want 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

    For Each wks In Worksheets
        'ignore errors in case there is only formulas
        On Error Resume Next
        wks.Cells.SpecialCells _
          (xlCellTypeConstants, 23).ClearContents
        On Error GoTo 0
    Next
    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.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (9097) applies to Microsoft Excel 2007, 2010, and 2013. 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

Pop-up Comments

Want to see what a comment says just by moving the mouse? Here's how.

Discover More

Finding Fields

Fields allow you to add simple dynamic content to your document. Here's how you can find the fields when you need to know ...

Discover More

Changing Your Windows 8 Account Picture

Want to personalize your Windows 8 experience a bit more? One way is by attaching a picture to your account, as discussed in ...

Discover More

Save Time and Supercharge Excel! Automate virtually any routine task and save yourself hours, days, maybe even weeks. Then, learn how to make Excel do things you thought were simply impossible! Mastering advanced Excel macros has never been easier. Check out Excel 2010 VBA and Macros today!

More ExcelTips (ribbon)

Can't Empty the Clipboard

The Clipboard is essential to move or copy information from one place in Excel to another. If you get an error when you try ...

Discover More

Copying to Very Large Ranges

Using the mouse to select a large cell range can be frustratingly slow. If you want to make copying to a large range of cells ...

Discover More

Deleting All Names but a Few

Want to get rid of most of the names defined in your workbook? You can either delete them one by one or use the handy macro ...

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}] in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 8Mpixels. 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 6 - 4?

2017-07-19 15:53:15

Holly

I'm not able to make this work on anything but plan numbers. Is there another way to do this for date formulas? I built a production scheduling tool and would like to remove all the dates but leave the formulas so people can start with a clean slate instead of placeholder dates.


2017-06-17 15:24:30

Peter

Pao

.ClearContents does not alter formats or validation

Mitchell

Why not name the data area 'Input' and then just delete the old values


2017-06-16 01:38:00

Pao

How to clear without clearing a formats and data validation?


2017-04-24 09:04:47

Mitchell Billion

Can you clear everything but the first row that are headers and keep all formulas


2017-02-22 20:56:31

Sherril

You probably know this already, but Step 2 of your instructions shows "Comments" selected, not "Constants".


2017-02-03 10:31:55

Valerie Fieldwebster

Great help. Thanks


2016-12-03 08:23:32

lakhan singh

How to possible that

sum formula worked but not delete formula or no edditing/correction in formula


2016-09-21 05:36:57

Dennis U

I would also appreciate advice if there is a possibility to delete only unprotected cells. Thanks a lot! Would make my life a lot easier.


2016-09-01 05:04:06

Francois

I used this method (F5 GoTO, Select "Constants", Unselect "text, the DEL) - but the application freezes and reboots, taking its time to do so. I am using Excel 2016.

Any advice?


2016-02-16 09:08:01

Paolo Gera

Good afternoon;
Is there any means to remove values in ALL UNLOCKED cells within a protected worksheet? If you remove all but formulas you'll get rid of all cells contents that might contain names and/or other complementary information which you do not want to eliminate.
Thanks in advance...


2016-02-16 08:16:42

Paolo Gera

Is there any means to remove values in ALL UNPROTECTED cells only? If you remove all but formulas you'll get rid of all cells that might contain names and/or other complementary information which you do not want to eliminate.
Thanks in advance...


2016-01-20 05:13:09

balthamossa2b

@David

The above macro should work fine. Have you allowed macro execution in Excel options? Are you using .xlsm or .xls files instead of .xlsx ?


2016-01-19 08:44:07

David

I have the same problem as Malika.

Can anyone advise.


2016-01-15 14:00:45

Sam

THANK YOU!!!!!!


2015-12-29 14:29:22

Malika Daniels

Good Afternoon,

Is there a way to remove the values of an Excel spreadsheet but keep the formulas? I have a 12 page Excel spreadsheet that I need to clear for the year 2016 but when I follow the instructions I found online, it erases the values and all the formulas I have saved. HELP!!
Thank you!


2015-01-23 09:26:59

Glenn Case

To address Wiily's cautionary final note in his 20 Jan post, when I do something like this, I typically add a msgbox with a warning and the ability to cancel the operation. That has saved me a few times...


2015-01-22 05:21:56

balthamossa2b

@Willy

Hmmm, seems you are right. I exclusively use On Error GoTo so I thought the On Error Resume behaved the same way.


2015-01-21 10:48:37

Willy Vanhaelen

@balthamossa2b

Nope, you're wrong. After an 'On Error Resume Next', all runtime errors will be ignored until the procedure ends or an 'On Error GoTo 0' is met. A call to another procedure will suspend it during that call.


2015-01-21 05:19:55

balthamossa2b

@Willy

On Error should be inside the loop. Say you have multiple sheets with no constants on them; the error will be triggered multiple times.

However once an On Error has been triggered (or the Resume instruction executed, in case you are using an On Error GoTo), you need to reload it to work; which means the second sheets without constants will give you an execution error.


2015-01-20 11:25:13

Willy Vanhaelen

There is no need to set 'On Error Resume Next' on and off for each worksheet. Just place it before the For Next statement and leave out 'On Error GoTo 0'.

Also 'Set wks = nothing' is unnecessary because it's the last statement of the macro and when it finishes the memory used by wks is freed anyway.

The 23 can also be left out because it's the default. The macro can thus be rewritten like this:

Sub ClearAllButFormulas()
Dim wks As Worksheet
On Error Resume Next 'ignore errors in case there is only formulas
For Each wks In Worksheets
wks.Cells.SpecialCells(xlCellTypeConstants).ClearContents
Next
End Sub

One final note: this is a very dangerous macro because when you run it accidentally in any workbook, everything except formulas in the entire workbook is gone. So, unless you know exactly what you are doing, the manual procedure described in this tip is preferred. You can always undo it when you are not satisfied with the result which is not the case when a macro does it.


2015-01-19 09:08:59

balthamossa2b

Couple questions about the macro:

1) What does the On Error GoTo 0 do? All errors will be caught by Resume Next, I don't see when this one would be triggered.

2) What is the 23 for? By checking the function on VBA I see that it's an optional argument called Value, but I don't see what it does.


2015-01-17 22:53:36

Thauhid

This tip shows how Excel saves time for the familiars.


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.