Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Set button to clear specific cells?

Status
Not open for further replies.

dkr1

Technical User
May 22, 2002
35
0
0
US
I would like to create a button at the bottom of my sheet to clear a group of cells. Is there an easy way to do this?

Thanks!
 
One easy way is to record a macro of you deleteing the cells you want and copy the macro code it developes to the button code.



[Blue]Blue[/Blue] [Dragon]

If I wasn't Blue, I would just be a Dragon...
 
Put the following code in a standard module

Public Sub ClearSpecificCells()
ThisWorkbook.Worksheets("Sheet1").Range("A5:O200").ClearContents
End Sub

Note, you will need to change the worksheet name and range to match the specified range on specified worksheet to delete the contents of the range.

Now, bring up the Form Toolbar

Click on the Command Button toolbar button

Select where on the worksheet you want to create the command button.

Pick the macro from the list.

Click on "OK"

While you at it and the command button still has the focus, you can change the caption of the command button by single click on the command button where you see the text, then change the text.

Ronald R. Dodge, Jr.
Production Statistician
Master MOUS 2000
When the going gets tough, the tough gets going.
 
Thanks to both!

rdodge...is there some code that will return to cell "A2" at the end of the macro?
 
If it's a must have in place, then you can use:

Range("A2").Select

But again, this would only be advised to be used in either at the end of the macro to set the active cell for the user or if there is no other way around the situation as I have ran into that situation, but it's extremely rare in the latter case.

Ronald R. Dodge, Jr.
Production Statistician
Master MOUS 2000
When the going gets tough, the tough gets going.
 
rdodge...that was just what I needed...much thanks!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top