Software & Applications

Guide to Wrapping Formulas with the ROUND Function in Excel Windows

Guide to Wrapping Formulas with the ROUND Function in Excel

Using a VBA Macro

A more effective way to modify all formulas in Excel by wrapping them in the ROUND function is to use a VBA Macro. Below is the VBA code to accomplish this:

Open the VBA window:

  • Press Alt + F11 to open the VBA window.

Create a new module:

  • In the VBA window, select Insert > Module to create a new module.

Enter the VBA code:

  • Copy and paste the following code into the module:

Sub WrapFormulasWithRound()
    Dim cell As Range
    Dim formula As String

    ' Loop through all cells in the selection
    For Each cell In Selection
        If cell.HasFormula Then
            formula = cell.Formula
            ' Wrap the formula with ROUND
            cell.Formula = "=ROUND(" & Mid(formula, 2) & ", 2)"
        End If
    Next cell
End Sub

Run the Macro:

  • To run the Macro, return to Excel and select the range of cells you want to apply this to (the cells containing formulas).
  • Press Alt + F8, select WrapFormulasWithRound, and then click Run.

This macro will wrap all formulas within the selected cells in the ROUND function, rounding to 2 decimal places.

 Thank for visit my website