Solved

VBA script to convert all formulas in values of all the sheets of the file

Posted on 2014-11-11
3
1,986 Views
Last Modified: 2014-11-12
Excel 2010:
How can I convert all formulas of all the sheets of the file in values, preserving formatting?
I tried by manually copying and pasting values over a whole sheet but it fails because there are many merged cells.

I need that because I used some INDIRECT formulas that require the external file sources to be opened and I cannot send these source files to the recipient...
Excel unfortunately doesn't cache the results of these formulas...
0
Comment
Question by:lucavilla
3 Comments
 
LVL 27

Accepted Solution

by:
Glenn Ray earned 400 total points
ID: 40436252
This code will loop through all worksheets in a workbook and convert all formula cells to their value.
Sub Replace_Formulas()
    Dim wbk As Workbook
    Dim ws As Worksheet
    Dim rng As Range
    Dim cl As Object
    
    Application.Calculation = xlCalculationManual
    Application.ScreenUpdating = False
    On Error Resume Next
    
    Set wbk = ActiveWorkbook
    For Each ws In wbk.Sheets
        Set rng = ws.Range("A1").SpecialCells(xlCellTypeFormulas, 23)
        If Not (rng Is Nothing) Then
            For Each cl In rng
                cl.Value = cl.Value
            Next cl
        End If
    Next ws
    Application.Calculate
    Application.Calculation = xlCalculationAutomatic
    Application.ScreenUpdating = True
    MsgBox "Done"
End Sub

Open in new window


Regards,
-Glenn
0
 
LVL 20

Assisted Solution

by:ltlbearand3
ltlbearand3 earned 100 total points
ID: 40436626
Depending on how often you need to accomplish this, you can probably do this with just straight Excel.  I assume you want to remove ALL formulas and replace them with their values.

First select all the sheets in the workbook by click the first sheet, then hold down the shift key and click the last sheet.  Now press Cntrl-A to select all cells on all sheets.  Now copy (Cntrl-C).  Now do a paste special and choose Values.  Then you can save the workbook as a new file that will no longer have any links or formulas.

No code required.
0
 

Author Closing Comment

by:lucavilla
ID: 40436797
Wonderful, thanks!!!
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction While answering a recent question (http:/Q_27311462.html), I created an alternative function to the Excel Concatenate() function that you might find useful.  I tested several solutions and share the results in this article as well as t…
Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now