**Please Note: **
This article is written for users of the following Microsoft Excel versions: 2007 and 2010. 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: Leaving a Cell Value Unchanged If a Condition Is False.

While using the IF function, Vineet wants to retain the old value in the cell if the condition is false. In other words, the value in a cell where the IF function is used should change only if the condition being tested by the IF function is true. By default, however, the IF function makes the value 0 if the condition is False.

The IF function can take up to three parameters. The first parameter is the comparison that is to be made, the second parameter is what should be returned if the comparison is true, and the third is what should be returned if the comparison is false. It is possible to leave off the last parameter, but if you do then Excel will return the value 0 if the comparison is false. (This is what Vineet is seeing returned by his IF function usage.)

The obvious solution, then, is to make sure that you provide the IF function with something that should be returned when the comparison is false. For instance, let's say that your formula is in cell B1 and you are comparing something in cell A1. The formula you use may look like this:

=IF(A1<10,"under ten",B1)

Note that the words "under ten" are returned if the value in A1 is less than 10. If this condition is not met, then the value in B1 is returned. Since this formula is in cell B1, this means that the previous value in the cell is returned if the condition is false.

It also means that the formula contains a circular reference. For circular references to work OK you need to let Excel know that it is OK for them to occur in your worksheet. Choose Tools | Options | Calculation tab and make sure the Iteration check box is selected. Excel will now allow the circular reference without complaint.

If you don't want to allow a circular reference in your worksheet, then the only recourse is to create a macro that updates the value in cell B1 based upon any changes to cell A1:

Private Sub Workbook_SheetChange(ByVal Sh As Object, _ ByVal Target As Range) ' See if the change is related to our cell If Not (Application.Intersect(Target, Range("A1")) _ Is Nothing) Then If Range("A1") < 10 Then Range("B1") = "under ten" End If End If End Sub

This simple macro, when added to the ThisWorkbook module, is executed every time there is a change in the workbook. If the value is cell A1 is changed (and only that cell), then the value is checked to see if it is less than 10. If it is, then the value in cell B1 is changed. If it isn't, then the value in cell B1 is left alone.

There is one "gottcha" that you need to keep in mind with any of the approaches discussed thus far, formula or macro. If the value in cell A1 is (let's say) 15, then cell B1 will contain what was there before, whatever it was. If you change the value in cell A1 to (let's say) 7, then B1 will change to "under ten." That's fine, but from that point on cell B1 will never appear to change. Why? Because if you then change cell A1 to a value greater than 10, cell B1 will contain (as just explained) what was there before. And, as you now understand, the value that was there before is the result of the previous true result, which was "under ten." Thus, true or false, the formula or macro from this point on displays the text "under ten."

*ExcelTips* is your source for cost-effective Microsoft Excel training.
This tip (8264) applies to Microsoft Excel 2007 and 2010. You can find a version of this tip for the older menu interface of Excel here: **Leaving a Cell Value Unchanged If a Condition Is False**.

**Create Custom Apps with VBA!** Discover how to extend the capabilities of Office 2013 (Word, Excel, PowerPoint, Outlook, and Access) with VBA programming, using it for writing macros, automating Office applications, and creating custom applications. Check out *Mastering VBA for Office 2013* today!

The MODE function is used to determine the most frequently recurring value in a range. This tip explains how to use the ...

Discover MoreWhen applying trigonometry to the values in a worksheet, you may need to convert radians to degrees. This is done by ...

Discover MoreGrading in schools is often done using numeric values. However, you may want to change those numeric values into letter ...

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

2018-05-14 22:34:18

thashi

thank you so much for this.. worked exactly how I wanted..!!

2018-04-04 02:55:46

Steve Jez

Chris,

This should do what you want

=IF(C4<20,C4,20)

HTH

2018-04-03 11:50:48

chirs

Q. How do I return the same value in D4 that is in C4 if the condition is not met (the formula is in D4). eg.If C4 is greater than or equal to 20 then I want D4 to show "20", but if C4 is less then 20, then I want D4 to return the same value that you see in C4 . ( C4 = 35, D4 =20)(C4=16,D4=16).

total load # 1 load # 2 load # 3

86 42

16

53 20

20 13

total 175 75 0 0

=IF(C4>=20,20,"")

=IF(C3>=42,42,"-")

2016-11-02 07:47:18

Gary Coleman

2016-02-02 17:45:24

alak

I have a similar just more complex issue, I would like to create the circular ref that puts but the current value of a cell. But I all ready have a false value that I need(as I don't want the amount appearing in the future months). I only want the amount from K9 to change for the current month and leave the month/s before what it was.

I've been trying nested IF and AND statements but can't seem to get it right.

=IF(C1<TODAY()+1,$K$29,IF(C1>TODAY()+1,0))

2016-01-24 06:43:26

Projects

Mr. Allen Wyatt,

Thanks for your help. I have one question. What to do if one have to retain different values in multiple column and rows (Cell's own value)?

Say

Column

A B C D E

with unlimited rows

2015-12-22 05:12:38

Felipe FAG

Right formula

=if(a1=b1,c1)

If false do nothing (a1<>b1)

do nothing and keep the old value.

Regards

2015-12-22 05:08:42

Felipe FAG

This formula will be a VBA.

Tks

2015-12-22 05:07:31

Felipe FAG

I'm need to add a formula:

=If(a1=b1,c1,e1).

If false do nothing and keep the old value in the cell.

Regards

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 © 2018 Sharon Parq Associates, Inc.

## Comments