Move a worksheet and paste it as values

waldymar

Board Regular
Joined
Feb 19, 2009
Messages
238
Dear All,

I need to copy and move a worksheet and save as values in a new workbook. I'm almost done just beside the pasting as values. I would appreciate much your help on that:

Code:
Sub moving()
Dim varPath As String
Dim WbOpen As Workbook
Set WbOpen = Workbooks.Add
varPath = codedraft.Range("b14").Value
datadraft.Copy before:=WbOpen.Sheets(1)
Application.DisplayAlerts = False
WbOpen.SaveAs varPath & "\General-" & Format(Date, "dd-mmm-yyyy") & ".xlsx"
Application.DisplayAlerts = True
WbOpen.Close
End Sub
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
What are codedraft and datadraft variables?
Code:
...
varPath = codedraft.Range("b14").Value
datadraft.Copy before:=WbOpen.Sheets(1)
...
 
Upvote 0
Code:
[COLOR="Blue"]Sub[/COLOR] moving()
    [COLOR="Blue"]Dim[/COLOR] varPath [COLOR="Blue"]As[/COLOR] [COLOR="Blue"]String[/COLOR]
    [COLOR="Blue"]Dim[/COLOR] WbOpen [COLOR="Blue"]As[/COLOR] Workbook
    [COLOR="Blue"]Set[/COLOR] WbOpen = Workbooks.Add
    varPath = codedraft.Range("b14").Value
    datadraft.UsedRange.Copy
    WbOpen.Sheets(1).PasteSpecial xlPasteValues
    Application.DisplayAlerts = [COLOR="Blue"]False[/COLOR]
    WbOpen.SaveAs varPath & "\General-" & Format([COLOR="Blue"]Date[/COLOR], "dd-mmm-yyyy") & ".xlsx"
    Application.DisplayAlerts = [COLOR="Blue"]True[/COLOR]
    WbOpen.Close
[COLOR="Blue"]End[/COLOR] [COLOR="Blue"]Sub[/COLOR]
 
Upvote 0
Code:
[COLOR=blue]Sub[/COLOR] moving()
    [COLOR=blue]Dim[/COLOR] varPath [COLOR=blue]As[/COLOR] [COLOR=blue]String[/COLOR]
    [COLOR=blue]Dim[/COLOR] WbOpen [COLOR=blue]As[/COLOR] Workbook
    [COLOR=blue]Set[/COLOR] WbOpen = Workbooks.Add
    varPath = codedraft.Range("b14").Value
    datadraft.UsedRange.Copy
    WbOpen.Sheets(1).PasteSpecial xlPasteValues
    Application.DisplayAlerts = [COLOR=blue]False[/COLOR]
    WbOpen.SaveAs varPath & "\General-" & Format([COLOR=blue]Date[/COLOR], "dd-mmm-yyyy") & ".xlsx"
    Application.DisplayAlerts = [COLOR=blue]True[/COLOR]
    WbOpen.Close
[COLOR=blue]End[/COLOR] [COLOR=blue]Sub[/COLOR]

unfortunately, it doesn't work. it gives me a mistake in this row:
Code:
WbOpen.Sheets(1).PasteSpecial xlPasteValues

in my original coding, the expression
Code:
before:=WbOpen.Sheets(1)
meant that the moved worksheet is paste in a new workbook just before the sheets(1).
 
Upvote 0

Forum statistics

Threads
1,224,598
Messages
6,179,820
Members
452,946
Latest member
JoseDavid

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