Solved

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

Posted on 2014-11-11
3
2,486 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
How to get Spreadsheet Compare 2016 working with the 64 bit version of Office 2016
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.

752 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