excel vba - clear contents of cell but not formula

  • Thread starter Thread starter chief
  • Start date Start date
C

chief

is there a way to set up something or even a macro which once i print m
sheet, it will erase the numbers which i have in my cells, but not th
formulas i have set up in the formula bar. the reason being is m
invoice system has to obviously be cleared after each transaction, bu
i don't want to lose the formulas i have set up
 
Chief

Sub ClearItOut()
Cells.Select
Selection.SpecialCells(xlCellTypeConstants, 1).Select
Selection.ClearContents
End Sub

You can do the same manually by CRTL + A to select all cells.

F5>Special>Constants>Uncheck all but "Numbers" and OK

With number cells selected, right-click and "Clear Contents"

Gord Dibben Excel MVP
 
You perhaps can do this manually. Go to the Edit menu, select Goto, then click
the Special button. In the next dialog, select Constants and Numbers. Then
click OK, and press the Del key to clear them.

Turn on the macro recorder when you do this manually to get the VBA commands
if you want to automate it.
 
I think I'd define a range name that encompassed all the cells I wanted to
clear. (There might be lots of labels on the worksheet that shouldn't be
cleared.)

Then select that range (just type it into the Name box)
and hit the delete key.

or via code:

worksheets("sheet1").range("cellstobecleared").clearcontents
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top