Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Formula in Excel 1

Status
Not open for further replies.

Tronsliver

Technical User
Sep 19, 2000
120
US
After entering a formula in a cell I added a commnad button that does a clear when clicked. The problem I having is that it also wipes out the formula. Is there a way to clear a cell of its value and retain the formula. Here is the code:

Range("D3:D20").Value = " "

Also is there a way to not have this "#VALUE!" show up in a cell after its been cleared.
 
Try something like :
Code:
Dim oCell As Range
For Each oCell In Range("D3:D20")
    If Not oCell.HasFormula Then
        oCell.Clear
    End If
Next
or
Code:
     Range("D3:D20").SpecialCells(xlCellTypeConstants, 23).Clear
"#VALUE!" should not show in a cell taht has been cleared, as it is the result of a formula. Typically it occurs if you try to apply a numeric function to include a text value, like adding a number to a blank space. If you clear your cells, make sure they are set to blank and not a space. The statement Range("D3:D20").Value = " ", does not clear the cells, but places a value of a space in the cell,. Use = "" instead of " ".

AC
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top