ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Worksheet Functions (https://www.excelbanter.com/excel-worksheet-functions/)
-   -   help creating a button (https://www.excelbanter.com/excel-worksheet-functions/211908-help-creating-button.html)

RAZ

help creating a button
 
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 ?

Otto Moehrbach[_2_]

help creating a button
 
Change Clear to ClearContents. HTH Otto
"Raz" wrote in message
...
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 ?




Dave Peterson

help creating a 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.

Raz wrote:

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 ?


--

Dave Peterson

Rick Rothstein

help creating a button
 
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.

--
Rick (MVP - Excel)


"Raz" wrote in message
...
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 ?



RAZ

help creating a button
 
thanks

"Rick Rothstein" wrote:

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.

--
Rick (MVP - Excel)


"Raz" wrote in message
...
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 ?




Rick Rothstein

help creating a button
 
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).

--
Rick (MVP - Excel)


"Raz" wrote in message
...
thanks

"Rick Rothstein" wrote:

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.

--
Rick (MVP - Excel)


"Raz" wrote in message
...
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 ?






All times are GMT +1. The time now is 09:18 AM.

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