excel vba - clear contents of cell but not formula

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
 
G

Gord Dibben

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
 
M

Myrna Larson

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.
 
D

Dave Peterson

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
 
Top