VBA Create Copy Paste Values of single worksheet

Bembridge7

New Member
Joined
Oct 15, 2019
Messages
2
Hi Guys

I am hoping someone can help me with this..So I am trying to create a copy of one worksheet and paste special values. I'd like to be able to choose a name for the worksheet and keep the worksheet within the existing workbook, moving the worksheet to the front. Apoligies if the format is not in line with requirements, this is my first post. I'm pretty sure this part is not correct for some reason - " Before:=ActiveWorkbook.Sheets(1)"

Here is my code:

Public Sub CopySheetToReport()
Dim newName As String

On Error Resume Next
newName = InputBox("Enter the name for the copied worksheet")

If newName <> "" Then
ActiveSheet.Copy.PasteSSpecial Paste:=xlPasteValues
Before:=ActiveWorkbook.Sheets(1)
On Error Resume Next
ActiveSheet.Name = newName
End If
End Sub

Any help would be much appreciated
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
Code:
Public Sub CopySheetToReport()
    Dim newName As String
    newName = InputBox("Enter the name for the copied worksheet")
    Application.ScreenUpdating = False
    If newName <> "" Then
        ActiveSheet.Copy Before:=ActiveSheet
        ActiveSheet.Name = newName
        Selection.Copy
        Selection.PasteSpecial Paste:=xlPasteAllUsingSourceTheme
        Selection.PasteSpecial Paste:=xlPasteValues
    End If
    Application.CutCopyMode = False
    Application.ScreenUpdating = True
End Sub
 
Last edited:
Upvote 0
Thank you Mohadin for coming back to me so quickly. The copy works perfectly, however I noticed the copy still contains formulae and is not paste valued but not sure why? Also, the worksheet appears before the active sheet and I am trying to move the coped sheet to the start of the workbook so it appears as the first worksheet once the macro has run. Is this the correct code to add in to ensure the copied worksheet is moved to the start:

ActiveSheet.Copy Before:=Worksheets("Sheet1")

Thanks again!



Code:
Public Sub CopySheetToReport()
    Dim newName As String
    newName = InputBox("Enter the name for the copied worksheet")
    Application.ScreenUpdating = False
    If newName <> "" Then
        ActiveSheet.Copy Before:=ActiveSheet
        ActiveSheet.Name = newName
        Selection.Copy
        Selection.PasteSpecial Paste:=xlPasteAllUsingSourceTheme
        Selection.PasteSpecial Paste:=xlPasteValues
    End If
    Application.CutCopyMode = False
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
Hi
For pasting values , it works fine here!!
Code:
[COLOR=#333333]ActiveSheet.Copy Before:=Worksheets("Sheet1")[/COLOR]
It will do the job only for the first time when sheet1 is the first one
so try
Code:
ActiveSheet.Copy Before:=Worksheets(1)
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,289
Members
452,631
Latest member
a_potato

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