Command Button to clear and reset the cell values.

WONGMEISTER

Board Regular
Joined
Jun 15, 2002
Messages
107
I'm not sure if this can be done in Excel or not. I'm more Access-grounded and have used command buttons to do all sorts of things in an Access form, but here it goes...

In an Excel spreadsheet, I have certain cells in which the user will input values. They are A1, B4, B5 and C4. After the user inputs these values, other cells (that have formulas) display values. This is used for "What-If" scenarios.

If the user wants to input different numbers for the "What-If" scenarios, I want the user to be able to click a command button, and this would reset the cells (A1, B4, B5 and C4) to their original blank values.

How can I do this with the command buttons? I tried creating a command button, but I can't figure out the proper syntax for the code, assuming that this is the correct method.

Thanks in advance.
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
Create a command button from the control toolbox, and use this as your code:
Code:
Private Sub CommandButton1_Click()

    Range("A1,B4,C4,B5").Select
    Selection.ClearContents
End Sub
 
Upvote 0
Select the cells you wish to clear. Use the CTRL key to select non-contguous cells. With them select, give them a Name(say myRange)
Now assign this macro to a command button.
Code:
Sub ReSetMe()
Dim cl As Range
For Each cl In Range("myRange")
    cl = ""
Next cl
End Sub

lenze
 
Upvote 0
Thanks Tempo.

Next question is, once I create my command button, and place the code, clicking the command button won't clear the cells. It only places the "circles" around the command button, as if it's in design view. How do I take it out of design view?

Thanks.
 
Upvote 0
Thanks TempoTours, VoG and Lenze,

I just figured it out. I simply need to click the 'Design' view.

Again, thanks for the code.

Take it easy,

Rich
 
Upvote 0
Click the design button on your toolbar (it's the one with the ruler, triangle and pencil)...if this button is depressed, your command button won't work.
 
Upvote 0

Forum statistics

Threads
1,214,864
Messages
6,121,986
Members
449,060
Latest member
mtsheetz

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top