Solved

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

Posted on 2014-11-11
3
2,664 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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
If you need to forecast numbers -- typically for finance -- the Windows and Mac versions of Excel 2016 have a basket of tools to get the job done.
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

630 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