Please Note: This article is written for users of the following Microsoft Excel versions: 2010, 2013, and 2016. 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.

Adjusting Values with Formulas

by Allen Wyatt
(last updated January 29, 2018)

8

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, and 2016. You can find a version of this tip for the older menu interface of Excel here: Adjusting Values with Formulas.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Controlling the Format of Cross-References

When you use fields to add cross-references to tables or figures, Word normally takes care of formatting the words used ...

Discover More

Three-Dimensional Transpositions

Excel makes it easy to transpose your data so that rows become columns and columns rows. It doesn't have a built-in ...

Discover More

Extracting Proper Words

If you've got a list of potential words, and you want to know which of those potential words are real, you'll appreciate ...

Discover More

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!

More ExcelTips (ribbon)

Selecting a Cell in the Current Row

Macros often need to select different cells in a worksheet. Here's how you can use macro commands to change which cell is ...

Discover More

Store Common Macros in the Personal Macro Workbook

Want your macros to be available regardless of the workbook on which you are working? Here's how to store them in the ...

Discover More

Sheets for Months

One common type of workbook used in offices is one that contains a single worksheet for each month of the year. If you ...

Discover More
Subscribe

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

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is 5 + 9?

2015-10-01 08:09:57

Barry

@Jason,

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

@Tim,

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

Jason

Some great comments here. I need a Formula or Macro to Add 500 to a cell which is used as part of a calculation to arrive at a final number.

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

Tim

Dear all,

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

I agree with Bryan, the macro does what is promised in the tip but I am stunned to see how the looping through the selected cells is done in such a complex way, while there is a very simple alternative in VB which produces almost self explanatory code: For Each … Next which I use in the following simple alternative:

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

I don't get any errors when using the macro, and I can't see any reason why you would. It's a bit clunkily written, but will transform =SUM(A1:A3) to =(SUM(A1:A3))*1.1, just as promised on the tin.


2014-01-06 14:55:31

Glenn Case

Actually, there is another way to add an adjustable "fudge factor" term to a range of numbers or formulae. It also uses Paste Special, but results in the adjustment you're after:

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

Hi Allen,

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.


This Site

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.

Newest Tips
Subscribe

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

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.