Please Note: This article is written for users of the following Microsoft Excel versions: 97, 2000, 2002, and 2003. If you are using a later version (Excel 2007 or later), this tip may not work for you. For a version of this tip written specifically for later versions of Excel, click here: Returning Zero When a Referenced Cell is Blank.

Returning Zero when a Referenced Cell is Blank

by Allen Wyatt
(last updated January 18, 2020)

2

If you have a formula in a worksheet, and the cell referenced by the formula is blank, then the formula still returns a zero value. For instance, if you have the formula =A3, then the formula returns the contents of cell A3, unless cell A3 is blank. In that case, the formula returns a value of zero.

This seems to be related to the idea that it is impossible for a formula to return a blank value, when "blank" is used synonymously with "empty." You can, however, expand your formula a bit so that it returns an empty string. Instead of using =A3 as your formula, you would use the following:

=IF(ISBLANK(A3),"",A3)

This formula uses ISBLANK, which returns either True or False, depending on whether the referenced cell (A3) is blank or not. The IF function then returns an empty string ("") if A3 is blank, or it uses the value in A3 if A3 is not blank.

Regardless of what the formula returns, you can still use its result in other formulas, and it will work fine. Even if it returns an empty string, it is still treated by other formulas as if it contained zero. In areas where treating the cell as if it contained zero might be problematic (such as when you are charting the results of the formula), then you can modify the formula a bit, as shown here:

=IF(ISBLANK(A3),NA(),A3)

This formula returns the #N/A error if A3 is blank. This error propagates through other formulas that reference the formula, but the #N/A error is ignored completely when charting.

While the above solutions are satisfactory for most people, some people would really like to see a target cell be truly blank if the source cell is blank. For instance, you might want cell B7 to be blank if cell A3 is blank. If you put a formula in cell B7 (as already discussed), then cell B7 is not truly blank—it contains a formula.

If this is your goal—true "blankness"—then you can only achieve it through the use of a macro. The macro will need to check to see if the source cell was changed. If it was, then whatever is in the source needs to be copied to the target cell.

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
    Dim rMonitor As Range
    Dim rTarget As Range

    Set rMonitor = Range("A3")
    Set rTarget = Range("B7")

    If Not Intersect(Target, rMonitor) Is Nothing Then
        rMonitor.Copy rTarget
    End If

    Set rMonitor = Nothing
    Set rTarget = Nothing
End Sub

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 (2174) applies to Microsoft Excel 97, 2000, 2002, and 2003. You can find a version of this tip for the ribbon interface of Excel (Excel 2007 and later) here: Returning Zero When a Referenced Cell is Blank.

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

Opening Word 2007 Files in Older Versions

Word 2007 uses a different file format than was used in previous versions of Word. This can cause some problems in ...

Discover More

Answering Questions in Order

It is not unusual to use Excel to gather the answers to users' questions. If you want your users to answer your questions ...

Discover More

Enhancing Word Documents with Dynamic Fields

Add a field to your document and you add dynamic content. Word provides a wide variety of fields that can be used in a ...

Discover More

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!

More ExcelTips (menu)

Starting Out Formulas

When you enter a formula from the keyboard, Excel only knows it is a formula if you start it with an equal sign. You can ...

Discover More

Matching Formatting when Concatenating

Convert a numeric value to text and you may be surprised by how Excel displays the value. Here's a run-down on exactly ...

Discover More

Viewing Formulas versus Results

Sometimes it is helpful to see the actual formulas in a cell, rather than the results of those formulas. Here's how to ...

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 one more than 3?

2020-07-15 04:19:53

Peter

Stuart, what you need is a formula that returns a string, specifically "". If that is not a problem, then you can do that with a macro. Something like this - or better.

Function SumDouble(rStart As Range, rEnd As Range) As String
Dim rr As Range, ss As Worksheet
Dim bSum As Boolean, nSum As Double
Dim sStart As String, sEnd As String

sStart = rStart.Parent.Name
sEnd = rEnd.Parent.Name

For Each ss In Sheets
bSum = (ss.Name = sStart) Or bSum
If bSum Then
Set rr = ss.Range(rStart.Address)
If VarType(rr.Value) = vbDouble Then nSum = nSum + Val(rr.Value)
If (ss.Name = sEnd) Then Exit For
End If
Next
SumDouble = nSum
End Function


2020-07-14 11:11:19

Stuart Morris

I am in excel hell right now and need some help....

I am working on a scorecard which has an overview tab and then several other tabs which are the data points for the overview tab (main scorecard) the overview tab pulls data from each tab by month and these formulas are entered for example like this ='tab2'!A1+'tab3'!A1+'tab4'!A1 etc etc

My issue is the cell in the overview page returns a zero until data is entered into the relevant tabs. I do not want the overview page to return a zero as I want to set conditional formatting for the cell to be green if the true value is actually zero.

I have have tried several different formulas such as ifblank or ifvlookup but nothing will return the cell blank but then allow a zero to show should the value in the other tabs be zero.

Any help would be greatly appreciated.... and my head hurts :-)


This Site

Got a version of Excel that uses the menu interface (Excel 97, Excel 2000, Excel 2002, or Excel 2003)? This site is for you! If you use a later version of Excel, visit our ExcelTips site focusing on the ribbon 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.