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)

24

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

Setting Print Quality

When printing information in a workbook, you may want to take advantage of the different print quality settings available ...

Discover More

Retrieving the Last Value in a Column

Need to get at the last value in a column, regardless of how many cells are used within that column? You can apply the ...

Discover More

Working with Imperial Linear Distances

Excel works with decimal values very easily. It is more difficult for the program to work with non-decimal values, such ...

Discover More

Program Successfully in Excel! John Walkenbach's name is synonymous with excellence in deciphering complex technical topics. With this comprehensive guide, "Mr. Spreadsheet" shows how to maximize your Excel experience using professional spreadsheet application development tips from his own personal bookshelf. Check out Excel 2013 Power Programming with VBA today!

More ExcelTips (ribbon)

Forcing Input to Uppercase

If you type information into a workbook, you may want to make sure that what you type is always stored in uppercase. ...

Discover More

Automatically Adding 20% to an Entry

When you are developing a worksheet for others to use, you may want to have entries in a particular cell (or cells) be ...

Discover More

Extracting Numbers within a Range

If you have a large number of values in a column, you may want to move the values that meet specific criteria to another ...

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 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 3 - 2?

2018-01-04 06:56:04

Ashraf

Is There any way to keeping the formulas same as its entered and changing the value as of our need?? Please help.!!


2017-10-04 10:20:18

senthil

Hi,
Please any one tell me to clear /reset the contents in cell, but don't disturb the Macros and formulas


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.