Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2014-11-11
3
Medium Priority
?
2,865 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 1600 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 400 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

Technology Partners: 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

Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

670 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