Edit code to paste multiple sheets as values into new workbook

tenvfa

New Member
Joined
May 3, 2017
Messages
1
The code from this forum is what I used as a starting point. I am trying to modify it to copy multiple sheets and paste them all as values, instead of just one sheet.

I copied multiple sheets using
Code:
worksheets(array(1,2,3)).copy
I think the problem is
Code:
With ActiveSheet.UsedRange
because it is only replacing the first sheet as values and leaving the remaining sheets as formulas.

What do I need to change so that all the sheets paste as values?
Code:
<code style="margin: 0px; padding: 0px; border: 0px; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; white-space: inherit;">[COLOR=#101094]Private[/COLOR][COLOR=#101094]Sub[/COLOR][COLOR=#303336] Workbook_BeforeClose[/COLOR][COLOR=#303336]([/COLOR][COLOR=#303336]Cancel [/COLOR][COLOR=#101094]As[/COLOR][COLOR=#101094]Boolean[/COLOR][COLOR=#303336])[/COLOR][COLOR=#303336]

Application[/COLOR][COLOR=#303336].[/COLOR][COLOR=#303336]DisplayAlerts [/COLOR][COLOR=#303336]=[/COLOR][COLOR=#7D2727]False[/COLOR][COLOR=#303336]
Worksheets[/COLOR][COLOR=#303336]([/COLOR][COLOR=#303336]Array[/COLOR][COLOR=#303336]([/COLOR][COLOR=#7D2727]"Sheet 1"[/COLOR][COLOR=#303336],[/COLOR][COLOR=#7D2727]"Sheet 2"[/COLOR][COLOR=#303336],[/COLOR][COLOR=#7D2727]"Sheet 3"[/COLOR][COLOR=#303336]).[/COLOR][COLOR=#303336]Copy
[/COLOR][COLOR=#101094]With[/COLOR][COLOR=#303336] ActiveSheet[/COLOR][COLOR=#303336].[/COLOR][COLOR=#303336]UsedRange
    [/COLOR][COLOR=#303336].[/COLOR][COLOR=#303336]Value [/COLOR][COLOR=#303336]=[/COLOR][COLOR=#303336].[/COLOR][COLOR=#303336]Value
[/COLOR][COLOR=#101094]End[/COLOR][COLOR=#101094]With[/COLOR][COLOR=#303336]
[/COLOR][COLOR=#101094]Set[/COLOR][COLOR=#303336] wbNew [/COLOR][COLOR=#303336]=[/COLOR][COLOR=#303336] ActiveWorkbook
wbNew[/COLOR][COLOR=#303336].[/COLOR][COLOR=#303336]SaveAs [/COLOR][COLOR=#7D2727]"L:\Performance Data\UK Sales\Sales (Latest).xlsx"[/COLOR][COLOR=#303336]
wbNew[/COLOR][COLOR=#303336].[/COLOR][COLOR=#303336]Close [/COLOR][COLOR=#7D2727]True[/COLOR][COLOR=#303336]
Application[/COLOR][COLOR=#303336].[/COLOR][COLOR=#303336]DisplayAlerts [/COLOR][COLOR=#303336]=[/COLOR][COLOR=#7D2727]True[/COLOR][COLOR=#303336]

[/COLOR][COLOR=#101094]End[/COLOR][COLOR=#101094]Sub[/COLOR]</code>
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.

Forum statistics

Threads
1,223,909
Messages
6,175,313
Members
452,634
Latest member
cpostell

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