ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   How can I save the formulas when running a macro? Need ASAP!! (https://www.excelbanter.com/excel-discussion-misc-queries/118770-how-can-i-save-formulas-when-running-macro-need-asap.html)

MLP

How can I save the formulas when running a macro? Need ASAP!!
 
I have a simple question...is there a way, via code, to only clear the
contents of a defined range of cells and allow the rest of the worksheet to
remain untouched? Seems simple, but I'm new to macros.

Gary''s Student

How can I save the formulas when running a macro? Need ASAP!!
 
Here is an example of clearing a defined range:

Sub clear_part()
Dim r As Range
Set r = Range("A1:C5")
r.Clear
End Sub

--
Gary's Student


"MLP" wrote:

I have a simple question...is there a way, via code, to only clear the
contents of a defined range of cells and allow the rest of the worksheet to
remain untouched? Seems simple, but I'm new to macros.


Gary''s Student

How can I save the formulas when running a macro? Need ASAP!!
 
If you need to keep formulae and clear only data:

Sub clear_part2()
Dim r As Range
Set r = Range("A1:C5").SpecialCells(xlCellTypeConstants)
r.Clear
End Sub
--
Gary's Student


"MLP" wrote:

I have a simple question...is there a way, via code, to only clear the
contents of a defined range of cells and allow the rest of the worksheet to
remain untouched? Seems simple, but I'm new to macros.



All times are GMT +1. The time now is 12:27 PM.

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