VBA Code to create new page

mrRam

New Member
Joined
Jan 26, 2023
Messages
4
Office Version
  1. 365
  2. 2021
Platform
  1. Windows
`Hello, I was trying to create a new sheet using a `command button` and a `message box` with the same format and formulas as the sheet before, with the `command button` at the same place as the previous sheet (to allow myself to create a new sheet in the future using this one), however i cannot seem to find a way to get the `command button` to be in the new sheet.
Sub ADD_sheet()
Dim ws As Worksheet
Dim wsNew As Worksheet
Dim strName As String Set
ws = ActiveSheet
strName = InputBox("enter new sheet name")
Set wsNew = Sheets.Add(After:=Sheets(Sheets.Count))
wsNew.Name = strName
ws.UsedRange.Copy
wsNew.Range("A1").PasteSpecial xlPasteFormulas
wsNew.Range("A1").PasteSpecial xlPasteFormats
Application.CutCopyMode = False`
End sub
should i add something to the code or is there another solution that can solve this issue ?
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
Try this
VBA Code:
Sub ADD_sheet()
Dim ws As Worksheet
Dim wsNew As Worksheet
Dim strName As String
Set ws = ActiveSheet
strName = InputBox("enter new sheet name")
ws.Copy After:=Sheets(Sheets.Count)
ActiveSheet.Name = strName
End Sub
 
Upvote 0
Solution
Try this
VBA Code:
Sub ADD_sheet()
Dim ws As Worksheet
Dim wsNew As Worksheet
Dim strName As String
Set ws = ActiveSheet
strName = InputBox("enter new sheet name")
ws.Copy After:=Sheets(Sheets.Count)
ActiveSheet.Name = strName
End Sub
Unfortunately it didn't work, still doesn't add the command button in the new sheet
 
Upvote 0
The sheet you're running the code from has a command button on it? Because this is basically creating a copy of that sheet.
 
Upvote 0
The sheet you're running the code from has a command button on it? Because this is basically creating a copy of that sheet.
Yeah but seeing that the command button is not in a cell, i think that's maybe why it doesn't apprear in the new sheet
 
Upvote 0
The marked solution has been changed accordingly. In your future questions, please mark the post as the solution that actually answered your question, instead of your feedback message as it will help future readers. No further action is required for this thread.
 
Upvote 0

Forum statistics

Threads
1,215,772
Messages
6,126,804
Members
449,337
Latest member
BBV123

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