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
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
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
 
Upvote 0
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.
 
Upvote 0
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:
Upvote 0

Forum statistics

Threads
1,214,782
Messages
6,121,532
Members
449,037
Latest member
tmmotairi

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