Making Command Buttons

  • Thread starter Thread starter Rick
  • Start date Start date
R

Rick

I am trying to make a button in a spreadsheet to clear a
certain area. Example: Click on button and it will clear
range B1-B5. What book would I need to get to tell me how
to do this.
Rick
 
Rick, assign this to a button
Sub Clear_Cells()
[B1:B5].ClearContents
End Sub


--
Paul B
Always backup your data before trying something new
Using Excel 2000 & 97
Please post any response to the newsgroups so others can benefit from it
** remove news from my email address to reply by email **
 
make the control toolbox toolbar visible (view=>Toolbars, select Control
Toolbox)

click on the button icon

goto the worksheet and click where you want the upper left corner, keep the
mouse down and drag down and to the right to make it the size you want and
release the mouse button.

You are now in design mode with the button on the sheet. In the control
toolbox toolbar you will see the upper left icon, the one with the drawing
triangle, appears depressed. This shows you are in design mode.

Double click on the commandbutton and you will be taken to the click event
of the commandbutton - in the sheet module, the code module associated with
the worksheet where event related code is placed.

the code will look like

Private Sub CommandButton1_Click()

End Sub

Add the line of code

Private Sub CommandButton1_Click()
Range("B1:B5").ClearContents
End Sub

to return to the worksheet, click on the excel icon in the upper right
corner of the Visual Basic editor or do Alt+F11

Now click on that upper left icon with the drawing triangle to get out of
design mode.

Click your button and B1:B5 will be cleared.

David McRitchie has some listings of Excel related tutorials. VBA tutorials
follow that list:

http://www.mvps.org/dmcritchie/excel/excel.htm#tutorials
 
Back
Top