Command button to deleat cell data in other sheet

vickypohadare

New Member
Joined
Jun 24, 2015
Messages
3
Can u pls help me...
How can i creat command button in sheet1 which can deleat data in sheet2 cell of excel
 

Some videos you may like

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK

Momentman

Well-known Member
Joined
Jan 11, 2012
Messages
4,066
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
WELCOME TO THE FORUM
1. With Sheet1 active, Go to Developer Tab(if it's not visible, go to Excel options>Customise Ribbon> Tick the check box beside the developer tab)
2. Under the CONTROLS group, click Insert>Form Controls>Button (Form Controls)
3. Drag and drop to size and Position the button
4. After the button is placed, Excel brings a dialog box asking you to choose a macro to asign to the button, Select the new button(at the right)
5. It opens the Visual basic editor and you can add a line like
Code:
Sheets("Sheet2").Range("A1:D4").Delete
to delete data on Sheet2 from A1 to D4.

The final code might look something like this:
Code:
Sub Button1_Click()
    Sheets("Sheet2").Range("A1:D4").Delete
End Sub
 

wellsr

Board Regular
Joined
May 16, 2015
Messages
130
If you want to delete ALL the data in Sheet2, follow these steps:

1) Open your VBA editor (Alt+F11) and insert a module.
2) Paste the following code:
Code:
Sub ClearSheet2()
    Sheets("Sheet2").Cells.Clear
End Sub
3) Make sure you're on Sheet1.
4) From your developer tab, click Insert>Button (Form Control).
5) Draw the button wher you want it.
6) Click ClearSheet2 on the "Assign Macro" dialog box.

That's it - now when you click the button on Sheet1, all the data in Sheet2 will clear.
 

vickypohadare

New Member
Joined
Jun 24, 2015
Messages
3
Thanks guys its very usefull to me..

When i use below code

Sheets("Sheet2").Range("A1:D4").Clear

Then whole formated cell is deleted

But u i want to clear only NUMBER or TEXT in that cell not the border and colour of that cell.
 
Last edited:

wellsr

Board Regular
Joined
May 16, 2015
Messages
130
I'm glad we could help! You can change .clear to .ClearContents to only delete the number/text.
 

Watch MrExcel Video

Forum statistics

Threads
1,122,491
Messages
5,596,477
Members
414,070
Latest member
DuncanLucas

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
Top