help creating a button

  • Thread starter Thread starter Raz
  • Start date Start date
R

Raz

Sub Button1_Click()
Range("A1:D10").Clear
Range("A12:D15").Clear
End Sub

I am using a button with this code above to reset those cells to blank
(deleting prevoius data). But it is deleting all the formatting also.
What do I need to change or add to the code above to clear the text and
numbers keeping all the formatting as it is.

Also should I use a Form control button or ActiveX control button ?
 
..clearcontents

And the choice of buttons is up to you. I like to use the controls from the
Forms toolbar. I find them easier to work with.

And if I have lots of them in the worksheet/workbook, I think they behave better
than the controls from the control toolbox toolbar.
 
As others have mentioned, ClearContents is the method you need to use. I
thought you might be interested in knowing that you can combine those two
statements into a single statement...

Sub Button1_Click()
Range("A1:D10,A12:D15").ClearContents
End Sub

Note that each disjointed range reference is separated by a comma and that
the entire reference is enclosed within the same set of parentheses.
 
thanks

Rick Rothstein said:
As others have mentioned, ClearContents is the method you need to use. I
thought you might be interested in knowing that you can combine those two
statements into a single statement...

Sub Button1_Click()
Range("A1:D10,A12:D15").ClearContents
End Sub

Note that each disjointed range reference is separated by a comma and that
the entire reference is enclosed within the same set of parentheses.
 
You are welcome. I just want to note one thing... I made a misstatement in
my original post... when I said "...and that the entire reference is
enclosed within the same set of parentheses" (which is true, but also
somewhat obvious), what I meant to say was "...and that the entire reference
is enclosed within the same set of quote marks" (that is, do NOT put each
disjointed range within its own quote marks).
 
Back
Top