ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Selection.ClearContents for data only (https://www.excelbanter.com/excel-programming/396467-selection-clearcontents-data-only.html)

Richard Lawson

Selection.ClearContents for data only
 
Is it possible to clear the data without clearing the formulas?

I have an area of the sheet which is mostly data which needs to be cleared
before updating. A few cells have formulas attached.

Rich



JE McGimpsey

Selection.ClearContents for data only
 
One way:

On Error Resume Next 'in case no constants
Selection.Cells.SpecialCells(xlCellTypeConstants). ClearContents
On Error GoTo 0


In article ,
"Richard Lawson" wrote:

Is it possible to clear the data without clearing the formulas?

I have an area of the sheet which is mostly data which needs to be cleared
before updating. A few cells have formulas attached.


Vergel Adriano

Selection.ClearContents for data only
 
maybe something like this:

Sub Test()
ActiveSheet.Cells.SpecialCells(xlCellTypeConstants ).Clear
End Sub


--
Hope that helps.

Vergel Adriano


"Richard Lawson" wrote:

Is it possible to clear the data without clearing the formulas?

I have an area of the sheet which is mostly data which needs to be cleared
before updating. A few cells have formulas attached.

Rich





All times are GMT +1. The time now is 07:27 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com