Convert Workbook To Values

lneidorf

Board Regular
Joined
May 20, 2004
Messages
97
Office Version
  1. 365
Platform
  1. Windows
Hi there.

I've been working on some code, that among other things, is to convert all content to values (i.e. formulas and references). This is designed to run against multiple files in a single folder, with some of the files rather complex.

This is giving me some trouble, particularly with complex files containing a lot of sheets.


Here's my first attempt, which does work, but takes a very long time to run:
Code:
Sub ConvertAllFormulaeToValues()
    Dim WSheet As Worksheet
    For Each WSheet In ActiveWorkbook.Worksheets
        WSheet.Select
        With WSheet.UsedRange
            .Cells.Copy
            .Cells.PasteSpecial xlPasteValues
            .Cells(1).Select
        End With
        Application.CutCopyMode = False
    Next WSheet
End Sub

As you can see, this code uses the clipboard, which is highly inefficient. I need a better way.

I attempted to revise this with code that will bypass the clipboard, but it errors out:
Code:
Sub ConvertAllFormulaeToValues()
    Dim WSheet As Worksheet
    For Each WSheet In ActiveWorkbook.Worksheets
        WSheet.Select
        With WSheet.UsedRange
            .Value = .Value 'This method bypasses the clipboard, making things much more efficient.
        End With
        Application.CutCopyMode = False
    Next WSheet
End Sub
This gives me a 1004 error ("Application-defined or object-defined error").

Any suggestions would be most appreciated.

Thanks!
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
I made some minor changes.

You have a hidden worksheet that cannot be selected. WSheet.Select

Code:
Sub ConvertAllFormulaeToValues()
    Dim WSheet As Worksheet
    For Each WSheet In ActiveWorkbook.Worksheets
        With WSheet.UsedRange
            .Value = .Value 'This method bypasses the clipboard, making things much more efficient.
        End With
    Next WSheet
    Application.CutCopyMode = False
End Sub
 
Upvote 0
Do you have any protected sheets?
Or merged cells?

Also you do not need to activate the sheet so you cab get rid of
Code:
WSheet.Select
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,176
Members
453,021
Latest member
Justyna P

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