**Please Note: **
This article is written for users of the following Microsoft Excel versions: 2010, 2013, 2016, 2019, and Excel in Office 365. If you are using an earlier version (Excel 2003 or earlier), *this tip may not work for you*. For a version of this tip written specifically for earlier versions of Excel, click here: Adjusting Values with Formulas.

There are times that you need to adjust the values stored in the cells of a worksheet. Most times, the tools provided by Paste Special will fit the bill just fine. For instance, you can use Paste Special to multiply or divide the values in a range of cells, as described in other issues of *ExcelTips.*

There is a drawback to using Paste Special, however—it changes the actual value, which you might not want to happen. Why? Because four months after making the adjustment to the values, you might not remember exactly what you did, or what the starting values were.

For this reason, you may find it more desirable to replace values with formulas that indicate what was done with your adjustment. For instance, you may have the value of 100 in cell B3, and you want to increase it by 10%. Using Paste Special you can easily change it to 110, but you may instead want to replace the value with the formula =100*1.1. With such a formula, there would be no question four months from now about the starting value or what you did to it.

The only way to adjust values with formulas is to use a macro, such as the following one:

Sub Adjust() Dim Target As Range Dim J As Integer Dim sForm As String Dim sMod As String Set Target = ActiveSheet.Range(ActiveWindow.Selection.Address) sMod = InputBox("Formula to add?") If sMod > "" Then For J = 1 To Target.Cells.Count If Target.Cells(J).HasFormula Then sForm = Target.Cells(J).Formula sForm = "=(" & Mid(sForm, 2, 500) & ")" sForm = sForm & sMod Target.Cells(J).Formula = sForm Else sForm = "=" & Target.Cells(J).Value & sMod Target.Cells(J).Formula = sForm End If Next J End If End Sub

To use this macro, select the cells you want to adjust, and then run it. You are asked for a formula to add to the cells. As an example, if you wanted to multiply the cells by 1.1, you would enter ***1.1** (the asterisk multiplication symbol, followed by 1.1). The macro then steps through each selected cell and makes the adjustments. If the cell contains a formula, then the formula is adjusted as you specified. If the cell contains anything else, then it is turned into a formula that includes your adjustment.

*Note:*

If you would like to know how to use the macros described on this page (or on any other page on the *ExcelTips* sites), I've prepared a special page that includes helpful information. Click here to open that special page in a new browser tab.

*ExcelTips* is your source for cost-effective Microsoft Excel training.
This tip (9486) applies to Microsoft Excel 2010, 2013, 2016, 2019, and Excel in Office 365. You can find a version of this tip for the older menu interface of Excel here: **Adjusting Values with Formulas**.

**Professional Development Guidance!** Four world-class developers offer start-to-finish guidance for building powerful, robust, and secure applications with Excel. The authors show how to consistently make the right design decisions and make the most of Excel's powerful features. Check out *Professional Excel Development* today!

Normally Excel positions a UserForm in the center of your screen. You may want to position the form elsewhere, more ...

Discover MoreOne of the most basic of programming structures is the conditional structure: If ... End If. This tip explains how this ...

Discover MoreIf you have a large, complex workbook, you may want to make sure that it is always calculated manually instead of ...

Discover More**FREE SERVICE:** Get tips like this every week in *ExcelTips,* a free productivity newsletter. Enter your address and click "Subscribe."

2015-10-01 08:09:57

Barry

You don't say if the cells you want adjusting contain just a number or have a formula.

This macro will cope with both. It will loop through all the cells that are selected and adjust the formula to add 500 to it, or if just a value create a formula to add 500 to the original value:

Sub Add500()

Dim rng As Range

For Each rng In Selection

With rng

If .HasFormula Then

.Formula = .Formula & "+500"

Else

.Formula = "=" & .Value & "+500"

End If

End With

Next rng

End Sub

To make it more generic you could add code to prompt for either the value you want added, a Named cell/formula/value to be added, or a cell reference itself (I'd recommend using absolute addressing in this case e.g. $A$1).

Sub AddAny()

Dim rng As Range

Dim tmp as String

tmp=Inputbox("Enter Value or Reference to be Added","AddAny Macro")

If tmp="" Then Exit Sub

For Each rng In Selection

With rng

If .HasFormula Then

.Formula = .Formula & "+" & tmp

Else

.Formula = "=" & .Value & "+" & tmp

End If

End With

Next rng

End Sub

2015-10-01 07:46:05

Barry

If you exclude cells which begin with "IF" this will catch all other cells including those that do not begin with "SUM"; so better to be exclicit and only catch those cell which explicitly begin with "SUM" if that is what you want.

This onlu catches those cells that begin with "SUM":

Sub CopyFormula()

Dim rCl As Range

For Each rCl In Range("C1:C17")

With rCl

If .HasFormula And Left(.Formula, 4) ="=SUM" Then

.copy .Offset(, 1).Resize(, 7)

End If

End With

Next rCl

End Sub

This will catch all cells that do not begin with "IF":

Sub CopyFormula()

Dim rCl As Range

For Each rCl In Range("C1:C17")

With rCl

If .HasFormula And Left(.Formula, 3) <>"=IF" Then

.copy .Offset(, 1).Resize(, 7)

End If

End With

Next rCl

End Sub

2015-09-30 13:11:50

For example I quote homes and the builder needs to make X amount I need to adjust the list price that is used to calculate taxes and commission etc and will give the final profit number. I am at loss.

Thanks

2015-08-25 12:11:14

I am not used in creating macros but found following which I need to have modified a bit.

Option Explicit

Sub CopyFormula()

Dim rCl As Range

For Each rCl In Range("C1:C17")

With rCl

If .HasFormula Then .copy .Offset(, 1).Resize(, 7)

End With

Next rCl

End Sub

Is it possible to exclude formulas begin with "If". I just want to copy those ones starting with "Sum".

Many thanks for your help

Regards

Tim

2014-01-11 11:18:03

Willy Vanhaelen

Sub Adjust()

Dim cell As Range, sMod As String

sMod = InputBox("Formula to add?")

If sMod = "" Then Exit Sub

For Each cell In Selection

If cell.HasFormula Then

cell.Formula = "=(" & Mid(cell.Formula, 2) & ")" & sMod

Else

cell.Formula = "=" & cell.Value & sMod

End If

Next cell

End Sub

2014-01-07 14:13:02

Bryan

2014-01-06 14:55:31

Glenn Case

If I have a range A2:A100 which all contain discrete values or formulae, and I want to increase the entire range by 10% but retain the record of the adjustment as noted, I can place 1.1 in cell C1, and "=$C$1" (without the quotes) into cell C2. Note, you need to have the absolute reference ($s) for this to work. I then copy cell C2 (Ctrl-C) and select the range A2:A100, and use Paste/Special/Multiply to paste. The result is that every cell in the range is now multiplied by $C$2, so if cell A2 contained 100 initially, after the operation, it will contain "=(100 * ($C$2))", which will result in 110 displayed in the cell. If the cell contained a formula, say "= A1*pi()", it will contain "=(A1*pi())*($C$2)" after the paste operation.

This quick trick makes is very easy to add an adjustment factor to a range.

2014-01-05 08:26:55

Peter Moran

Your macro needs to exclude formulas which begin with "=SUM", "=(SUM(", "=SUBTOTAL(" and =(SUBTOTAL("

as they will create errors if the designated Adjustment is applied to these formulas.

Got a version of Excel that uses the
ribbon interface (Excel 2007 or later)?
**This site is for you!** If you
use an earlier version of Excel, visit
our *ExcelTips* site focusing on the menu interface.

**FREE SERVICE:** Get tips like this every week in *ExcelTips,* a free productivity newsletter. Enter your address and click "Subscribe."

Copyright © 2019 Sharon Parq Associates, Inc.

## Comments