Change the formula in the cells in a range to values using VBA in Microsoft Excel

In this article, we will learn how to change the formula in the cells in a range to values using VBA in Microsoft Excel.

Raw data for this example consists of sales data. Sales data contains information regarding number of items sold by employees in different cities. Last row and column contains the sum formula for finding the total number of items sold in a particular city by a particular employee.

We would like to convert all the formulas in the active sheet to values. To convert all the formulas to values, we have created a macro “ChangingFormulasToValue”. This macro can be run by clicking the “Convert formulas to values” button.

ArrowMain

ArrowOutput

In the snapshot, one can see formula in H18 cell is converted to value.

Code explanation

Set SourceRng = Range("A1", Range("A1").SpecialCells(xlCellTypeLastCell))

Above code is used to assign all cells starting from cell A1 to the last cell in the workbook as range.

SourceRng.Value = SourceRng.Value

Above code is used to assign the cell value skipping the formula

 

Please follow below for the code

Option Explicit

Sub ChangingFormulasToValue()

'Declaring variables
Dim SourceRng As Range

'Specify all cells in the active sheet as range
Set SourceRng = Range("A1", Range("A1").SpecialCells(xlCellTypeLastCell))

'Assigning only value of the cell skipping formula of the cell
SourceRng.Value = SourceRng.Value

End Sub

 

If you liked this blog, share it with your friends on Facebook. Also, you can follow us on Twitter and Facebook.

We would love to hear from you, do let us know how we can improve our work and make it better for you. Write to us at info@exceltip.com

Users are saying about us...

  1. Great One question If I want the formula in a cell in a work sheet to change to value only it a cell value in another worksheet changes
    What are the changes required. eg in cell b5 in a sheet contains value 24, this value is divided into 12 monthly instalments. in another worksheet in say cell c5using b5/12 .after 12 months if b5 is changed then the formula in c5 should be changed to values without a formula and the new value is calculated in d5 what changes are required
    Tks

Leave a Reply

Your email address will not be published. Required fields are marked *

Terms and Conditions of use

The applications/code on this site are distributed as is and without warranties or liability. In no event shall the owner of the copyrights, or the authors of the applications/code be liable for any loss of profit, any problems or any damage resulting from the use or evaluation of the applications/code.

Visit Us On TwitterVisit Us On FacebookVisit Us On Youtube