# Excel VBA: Convert Formula to Value Automatically (2 Easy Methods)

In this article, Iâ€™ll show you how you can convert a formula of a worksheet to its value automatically using Excel VBA.

Excel VBA: Convert Formula to Value Automatically (Quick View)

Sub Convert_Formula_to_Value_1()

Sheet_Name = "Sheet1"

Set Cell_Range = Worksheets(Sheet_Name).UsedRange

For i = 1 To Cell_Range.Rows.Count
Â Â Â  For j = 1 To Cell_Range.Columns.Count
Â Â Â Â Â Â Â  Cell_Range.Cells(i, j) = Cell_Range.Cells(i, j).Value
Â Â Â  Next j
Next i

End Sub

## Convert Formula to Value Automatically in Excel VBA: 2 Suitable Methods

So, without further delay, letâ€™s go to our main discussion today. Here weâ€™ve got a worksheet called Sheet1 that contains the names of some candidates, their marks in written and viva of a recruitment test, the average marks, and a recommendation mentioning whether they are selected or not.

The average marks and the recommendation columns contain formulas.

Our objective is to convert the formulas to values using a VBA code.

We can develop the VBA code in two methods.

### Method 1: Convert Formula to Values Automatically by an Iteration in Excel VBA

You can convert all the formulas of a worksheet to values by iterating through a for-loop. Weâ€™ll replace the content in each cell of the worksheet with its value.

The complete VBA code will be:

â§­ VBA Code:

Sub Convert_Formula_to_Value_1()

Sheet_Name = "Sheet1"

Set Cell_Range = Worksheets(Sheet_Name).UsedRange

For i = 1 To Cell_Range.Rows.Count
Â Â Â  For j = 1 To Cell_Range.Columns.Count
Â Â Â Â Â Â Â  Rng.Cells(i, j) = Cell_Range.Cells(i, j).Value
Â Â Â  Next j
Next i

End Sub

â§­ Output:

Run this code (Donâ€™t forget to change the name of the worksheet according to your need). Itâ€™ll convert all the formulas of the worksheet to their values.

### Method 2: Convert Formula to Values Automatically by Copying and Pasting in Excel VBA

You can also convert the formulas of a worksheet to their values by first copying them and then pasting them. For pasting, weâ€™ll use the PasteSpecial method of VBA setting the Paste property to xlPasteValues.

The complete VBA code will be:

â§­ VBA Code:

Sub Convert_Formula_to_Value_2()
Sheet_Name = "Sheet1"
Set Rng = Worksheets(Sheet_Name).UsedRange
Rng.Copy
Worksheets(Sheet_Name).Range(First_Cell).PasteSpecial Paste:=xlPasteValues
Application.CutCopyMode = False
End Sub

â§­ Output:

Run this code (Again donâ€™t forget to change the worksheet name). Itâ€™ll convert all the formulas of the worksheet to their values again.

## Developing a Macro to Convert Formula to Value Automatically Using the VBA Codes

Weâ€™ve seen two different VBA codes to convert formulas to values automatically in a worksheet in Excel. Now weâ€™ll see how we can develop a Macro using the codes.

â§ª Step 1: Opening the VBA Window

Press ALT + F11 on your keyboard to open the Visual Basic window.

â§ª Step 2: Inserting a New Module

Go to Insert > Module in the toolbar. Click on Module. A new module called Module 1Â (or anything else depending on your past history) will open.

â§ª Step 3: Putting the VBA Code

This is the most important step. Insert any of the two given VBA codes in the module.

â§ª Step 4: Running the Code

Click on the Run Sub / UserForm tool from the toolbar above.

The code will run. All the formulas of your input worksheet will be converted to their values automatically.

## Things to Remember

• In method 2 of developing the codes, we used the xlPasteValues property of VBA. But besides this, there are 11 more properties to paste in VBA. If interested, you can have a look here.

## Conclusion

Therefore, this is the process to develop a VBA code to convert the formulas of a worksheet to their values automatically. Do you have any questions? Feel free to ask us.

## Related Articles

<< Go Back to Convert Formula to Value in Excel | Excel Formulas | Learn Excel

Get FREE Advanced Excel Exercises with Solutions!
Rifat Hassan

Rifat Hassan, BSc, Electrical and Electronic Engineering, Bangladesh University of Engineering and Technology, has worked with the ExcelDemy project for almost 2 years. Within these 2 years, he has written over 250 articles. He has also conducted a few Boot Camp sessions on effective coding, especially Visual Basic for Applications (VBA). Currently, he is working as a Software Developer to develop and deploy additional add-ins to enhance the customers with a more sophisticated experience with Microsoft Office Suits,... Read Full Bio

We will be happy to hear your thoughts

Advanced Excel Exercises with Solutions PDF