Delete a button in a worksheet from macro

macro_user

Board Regular
Joined
Mar 9, 2009
Messages
101
hi...
i have a basic sheet say sheet1 which has a button say button1 which invokes a macro... now, i need to copy sheet1 and generate a report in it... so, i copy the sheet1 from my macro and paste it at the end and renaming it (all from the macro)... i then generate the report... but in this report, there's this button1 in the new sheet which i do not want... how do i delete the button from the macro???
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
How about setting the properties on the original button to not allow it to be copied along with your data?

Right click your button:
Choose "Format."
On Properties tab, check "Don't move or size with cells".
 
Upvote 0
Nope... tat isn't working... is there any other way? like cells(1,"C").clearcontents or clearformats or anything?
 
Upvote 0
Greetings macro_user,

You fail to say whether the "button" is from the Forms toolbar or Control Toolbox. Presuming an ActiveX CommandButton, maybe something like:

Code:
Sub ex()
Dim wksNew As Worksheet
    
    ThisWorkbook.Worksheets("Sheet1").Copy _
        After:=ThisWorkbook.Worksheets(ThisWorkbook.Worksheets.Count)
    
    Set wksNew = ActiveSheet

    wksNew.Name = "NewSheet"
    wksNew.Shapes("CommandButton1").Delete
End Sub

Hope this helps,

Mark
 
Upvote 0
gr8.. the copy paste part is perfect... and i apologize for not telling wat type of button it is... it's a Form Control button... does the same thing work for both types of controls??? Form or ActiveX?
 
Upvote 0
As to deleting a button, if you just have a button or two, yes - using Shapes(index or name) should work. To find the name of the button, right-click on it, and look in the name box.

Code:
   '...code...
 
wksNew.Shapes("Button 1").Delete
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,908
Messages
6,122,186
Members
449,071
Latest member
cdnMech

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