![]() |
![]() |
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
New Member
Join Date: May 2002
Posts: 3
|
I would like to have a created button on my spreadsheet that when pressed will clear multiple cells of its data...How can this be done.
Any info is greatly appreciated!!! Thanks SeanM |
|
|
|
|
|
#2 |
|
Board Regular
Join Date: Feb 2002
Location: United Kingdom
Posts: 68
|
First you need to define the cells to be cleared. If it is a static range of cells that will be cleared each time then naming the range is the starting point.(Insert/Name/Define)
Then, if you use the macro recorder, following these steps once your recorder is running: Edit/Go To/ type name of range/OK Then Edit/Clear/Contents End macro. As for assigning the macro to a button: View/Toolbars/Forms. Click on button, drag onto spreadsheet. Text box will ask you to assign a macro - select teh one you just recorded. I think thats all the steps Nobby |
|
|
|
|
|
#3 |
|
Legend
Join Date: Feb 2002
Location: Minneapolis, Mn, USA
Posts: 9,704
|
Write the macro:
Code:
sub clr [a1:b25].clearcontents 'a1 through b25 go bye-bye end sub Click the button, draw it, you should be prompted to assign a macro, highlight clr and assign it. |
|
|
|
|
|
#4 |
|
Board Regular
Join Date: Apr 2002
Location: Sarasota, FL
Posts: 1,539
|
If you don't need to specify a specific range of cells each time, just record a macro of you clearing what you need to clear, name it, then insert a button into your sheet that executes the macro. Otherwise, you will need either a userform, or have Excel pull your clear range from the sheet itself and assign the range values to variables in your macro.
|
|
|
|
|
|
#5 |
|
Board Regular
Join Date: Apr 2002
Posts: 85
|
To clear all cells use:
cells.select selection.clear 'clears formula, data,etc or try selection.clearcontents 'which will clear data and not formulas and formatting. For a range try: Range("A1:Z50").select selection.clear |
|
|
|
|
|
#6 |
|
Board Regular
Join Date: Mar 2002
Location: England, UK.
Posts: 526
|
waderw,
you don't need select selection there, Range("A1:Z50").clearcontents does the trick. RET79 |
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|