copy, move, rename sheet- without buttons?

darro

Board Regular
Joined
Mar 10, 2009
Messages
208
I have this code:

Code:
Sub move()
sn = InputBox("Enter Sheet Name")
    ActiveSheet.Copy after:=ActiveWorkbook.Sheets(ActiveWorkbook.Sheets.Count)
    ActiveSheet.Name = sn
MsgBox "New Sheet Added"
End Sub

This works well but I have a few problems.

1. If I click Cancel on the Input Box I get an error and it still adds a sheet anyway, just with no new name.
2. It has the macro button on the new sheet, ideally I would like this not to be copied over.


Can anyone figure out what I need to do to get this to work?

Thanks for any help, much appreciated
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
1. Normally when I use application boxes I have statement that accounts for no.

I think if you had an if statement where sn = false then exit sub you would be ok

If sn = False Then
Exit Sub
Else...

2. ActiveSheet.Shapes("Button 1").Select
Selection.Delete

Should delete the button for you.
 
Upvote 0
This should work for you, assuming you have only one button and its a regular form control button.


PHP:
Sub move()
 
sn = Application.InputBox("Enter Sheet Name")
If sn = False Then
Exit Sub
Else
    ActiveSheet.Copy after:=ActiveWorkbook.Sheets(ActiveWorkbook.Sheets.Count)
    ActiveSheet.Name = sn
MsgBox "New Sheet Added"
End If
If ActiveSheet.Shapes.Count > 0 Then
ActiveSheet.Shapes("Button 1").Select
Selection.Delete
Else
End If
 
End Sub
 
Upvote 0
When you insert a control normally you have the option of picking an activex control or a form conrtol. They both look the same but are different when working with vba.

Odds are its the form control.
 
Upvote 0
Hi.

This works well. However, it does not delete the button if it's not Button 1. How can I specify the button number I want deleted?

This is so close to perfect.

Thanks for your help?
 
Upvote 0
An easy way to check the name of the button is to right click on it, the name should appear just left of the formula bar. Try changing the ("Button 1") to match yours.
Hope that helps.
 
Upvote 0

Forum statistics

Threads
1,224,603
Messages
6,179,850
Members
452,948
Latest member
UsmanAli786

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