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

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
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,223,904
Messages
6,175,295
Members
452,633
Latest member
DougMo

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