Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have an Excel 2010 workbook that contains a number of individual worksheets. The cells on one of the sheets are linked to individual cells on two other worksheets in the same workbook. I'm using a direct cell reference that essentially says that whatever value is entered into a particular cell on one sheet also populates cells on two other sheets. I used the (=) function with the cell reference to accomplish this.

The issue I'm running into is that, even when the primary cell is left blank, the cells that populate from that primary cell will display 0, rather than remaining blank themselves.

I want the subordinate cells to remain blank if the primary cell they're linked to is blank.

share|improve this question
    
My formula is very long, for me also the IF construction is hardly acceptable, good question but I too did not find good enough answer. {= IFERROR( INDEX(NEPŘÍMÝ.ODKAZ("EsZkouska");SMALL(KDYŽ((INDEX(NEPŘÍMÝ.ODKAZ("EsZkouska");;1‌​;1)="ČSN721180")*(INDEX(NEPŘÍMÝ.ODKAZ("EsZkouska");;9;1)="RC_P_B");ŘÁDEK(NEPŘÍMÝ.‌​ODKAZ("EsZkouska"))-MIN(ŘÁDEK(NEPŘÍMÝ.ODKAZ("EsZkouska")))+1;"");1);17;1);"")} – Vojtěch Dohnal Jul 25 '14 at 11:32
    
It is possible to use IF construction combined with this approach: stackoverflow.com/questions/22359452/…. Like this you can create named formulas and use them in your simple IF statement... – Vojtěch Dohnal Jul 25 '14 at 11:42

13 Answers 13

You need to force Excel to treat the contents of the cell as a text value instead of a number, which it does automatically with blank values.

=A2 & ""

This will force Excel into making that cell reference a text value, thus preventing the conversion of blanks into zeroes.

share|improve this answer
2  
Wow!  I can't believe that it turned out to be so simple! – Scott Apr 29 '15 at 22:03

Here are three answers:

1) Letting other.cell.reference represent the reference formula that you currently have after the = (e.g., Sheet17!$H$42), replace that link reference with

=IF(other.cell.reference<>"",other.cell.reference, "")

2) Set the “Number” format of your linked cells to “Custom”: General;–General;.

3) In “Excel Options”, “Advanced” page, “Display options for this worksheet” section, clear the “Show a zero in cells that have a zero value” checkbox.  Warning: this will cause all zeroes in the worksheet to disappear.

share|improve this answer
    
The first option is sub-optimal, as it requires entering (or copying) your formula twice within the cell. It can be especially nasty when you have a really long formula, and then need to edit (or worse, debug) that formula later. The second option doesn't seem to be working for me, but maybe I'm doing it wrong. The third is definitely not ideal since the scope of its effect is much broader than one might truly desire. Are there really no better options? – Iszi Sep 18 '13 at 18:32
    
@Iszi: Regarding the first option: I’m not talking about entering a formula twice. As per the original question, I’m talking about a situation where Q1 contains a (really long) formula and A1 contains =Q1; we want to change A1 to =IF(Q1<>"", Q1, ""), which you should never need to change again. “Are there really no better options?” Well, this question has been idle for nine months, and this is all that has been posted. If these answers aren’t good enough for you, post a new question, or put a bounty on this one. – Scott Sep 18 '13 at 19:08
    
That's more or less the same thing. Though it does resolve some of the cumbersomeness of having to troubleshoot two instances of one formula within one cell, it also complicates things a bit by adding another (otherwise unnecessary) cell or group of cells to the mix. Unfortunately, I suppose there really isn't another "nice and clean" answer for this, though. – Iszi Sep 18 '13 at 19:52
    
I did post a related question awhile back and the only worthwhile answer that's different from what's here involved a VBA script. – Iszi Sep 18 '13 at 19:52

I too did not find a better solution than the Scott's one.

But combined with the approach from here it could be almoste bearable, I think:

http://www.ozgrid.com/Excel/named-formulas.htm

Let's say I have formula like this

= IFERROR( INDEX(INDIRECT("EsZkouska");
  SMALL(IF((INDEX(INDIRECT("EsZkouska");;1‌​;1)="ČSN721180")*(INDEX(INDIRECT("EsZkouska");;9;1)="RC_P_B");
  ROW(INDIRECT"EsZkouska"))-MIN(ROW(INDIRECT("EsZkouska")))+1;"");1);17;1);"")

This formula reads cell value from a data sheet using conditional select and presents them on another sheet. I have no control over cell formating on the data sheet.

I go to Insert > Name > Define and in the "Names in workbook" I create new Name "RC_P_B". Then into the "Refers to" field I copy my formula (without {} characters - it is array formula).

Then you can use Scott's formula whithout having to repeat the whole formula text:

 {=IF(RC_P_B<>""; RC_P_B;"---")}

I believe this is better than to copy the whole formula.

share|improve this answer

I simple don't use a formula to overcome this problem. All I do is to conditionally format cells to font color white if cell value equals 0.

share|improve this answer
    
This has the obvious issue with cells which have a legit 0 value. – Dmitry Grigoryev Oct 2 '15 at 22:57

If the linked cell is non-numeric you can use an IF statement with ISTEXT:

=IF(ISTEXT(Sheet1!A2), Sheet1!A2, "")
share|improve this answer
1  
But if the referenced cell (Sheet1!A2, in your example) contains a number, this will display a null string. – Scott Dec 6 '12 at 21:35
    
Yeah it wasn't clear from the question what data is in the referenced cell. I figured if it was numeric he would want the zeros. – Brad Patton Dec 6 '12 at 21:36

IF your reference data is only either a numeric type (non-text) or empty, and you may have 0's, then this is my preferred approach, with only entering formula once. Admittedly, a slightly indirect way, but it is best I think because:

  • you don't need extra cells to put the formula in and then reference the second cells
  • you don't need to type the formula twice
  • this method differentiates between a zero value and an empty cell
  • doesn't require VBA
  • doesn't require Named Ranges

Downfall: If you need text data returned this this will not work. For text data my preferred method is using number format as mentioned in other answers above.

=IFERROR((A1 & "") * 1,"")

A1 in this instance can be replaced by any cell, including another sheet, workbook, or INDIRECT().

Notes on how this works:
IFERROR() - second argument is set to empty string, so if an error occurs we get an empty string. So we need to make sure if the source cell is empty, an error is triggered.

Numeric method: Stringify the source value, then multiply by 1. Literal emtpy string * 1 = #VALUE, String with numeric is auto-converted to numeric and no error occurs.

share|improve this answer
    
Interesting.  Why do you think you need "" & A1 & ""?  When does that produce different results from A1 & "" or "" & A1? – G-Man Apr 28 '15 at 6:24
    
@G-man : correct, and preferable. Thanks I have updated answer. – rayzinnz Apr 28 '15 at 22:48

There is another trick: set the soucre empty cell to formula ="". See the detailed description here.

share|improve this answer

I have long searched for an elegant solution to this issue.

I have used formula =if(a2="","",a2) for years, but I find it to be a bit cumbersome.

I tried above suggestion =a2&"" and although it does appear to work it shows a number that is actually text so number formatting cannot be applied and no statistical operations work, such as sum, average, median, etc., so if it's workable numbers you're looking for this doesn't fit the bill.

I experimented with some of the other functions and found what I think is the most elegant solution to date. Continuing the above example:

=CELL("contents",A2)

returns a numerical value that can be formatted as a number and it returns a blank when the referenced cell is blank. For some reason, this solution doesn't seem to appear in any of the online suggestions I've found, but it

share|improve this answer
1  
I just tried this in Excel 2013.  When A2 is blank, this displays 0.  Are you sure you're not doing anything with the formatting? – Scott Jun 11 '15 at 4:09
Public Function FuncDisplayStringNoValue(MyCell As Variant) As String

Dim Result As Variant

If IsEmpty(MyCell) Then

   FuncDisplayStringNoValue = "No Value"

Else
   Result = CDec(MyCell)

   Result = Round(Result, 2)

   FuncDisplayStringNoValue = "" & Result

   End If

End Function
share|improve this answer

What worked for me in Office 2013 was:

=IF(A2=""," ",A2)

Where on the first set of quotations there is no space, and on the second set there is a space.

Hope this helps

share|improve this answer
    
Why do you need the space in the second set of parentheses? Doesn't =IF(A2="", "", A2) work just as well? How would that be different from =IF(A2<>"", A2, "")? Then how is that different from the highest-voted answer, which was given over two years ago? – G-Man Mar 17 '15 at 22:44

I had a similar problem, and I think I found a method for you. It fixed my issues.

If you want column C to reference column A, and only write a formula for the reference cell, you would use this and drag down the column.

=A1

However, there may be source cells in column A that are blank and need to remain blank in the reference cells in column C, you can use this and drag the down column.

=T(A1)

As far as cell formatting goes, the reference (columnn C) will need to be general.

share|improve this answer
    
Alas, this was a drive-by question — the OP came to Super User (almost three years ago), asked this one question, and never came back.  So, we may never know the details of his situation.  But, a major (if not the major) function of Excel is to crunch numbers.  If the source data (column A, in your example) contains numbers, your answer fails to populate the target cells with the numeric data. – Scott Sep 1 '15 at 11:36
    
Make sure your cell formating in the cells containing the =T () formula is General rather than Text. Because where I've used it, it totally shows numbers. – Will Prater Sep 2 '15 at 20:39
    
I checked.  It's General, and it's coming up blank.  (Excel 2013) – Scott Sep 2 '15 at 21:01
    
The problem could be that you're using 2013, my answer I'd for 2010. – Will Prater Sep 3 '15 at 22:38

Solution:
=IF('Wk1 Data-replace w dt bgn & end'!C2>0, 'Wk1 Data-replace w dt bgn & end'!C2, "")

Explanation:
To solve this problem I used two sets of If commands.

Part one of command:
I told the cell to display the contents of the reference cell if the reference cell contained data (Excel interprets this as the cell having a value larger than 0)

Part two of command:
I told it how to behave if there was no data; "" means leave blank

Note: Wk1 Data-replace w dt bgn & end'!C2 is my reference cell.

share|improve this answer
    
(1) This will display blank even if the referenced cell contains 0 or a negative number.  The question wants the linking cell to be blank only if the referenced cell is blank.  (2) If you make the obvious change and change this to =IF('Wk1 … bgn & end'!C2<>"", 'Wk1 … bgn & end'!C2, ""), it becomes equivalent to an answer that has been given approximately four times already. – G-Man Nov 30 '15 at 6:41

Go to Format Cells.

Then select custom format, and enter the following: 0;-0;;@

share|improve this answer
1  
Can you explain what this does? Thanks. – fixer1234 Sep 25 '15 at 20:18
1  
This does pretty much the same thing as the second option of my answer to this question («Set the “Number” format of your linked cells to “Custom”: General;–General;. ») — namely (a) if the value is a positive number, display its integer absolute value; (b) if the value is a negative number, display its integer absolute value, preceded by -; (c) if the value is zero, display nothing; and (d) if the value is not a number, display its text value.  … (Cont’d) – Scott Sep 25 '15 at 21:26
1  
(Cont’d) …  However, this version has the drawback (i.e., error) that it rounds non-integer numbers to the nearest integer.  (General gives you the default format for numbers, including decimal digits as necessary (but not including the - sign).)  Also, the final ;@ seems to be unnecessary (i.e., it seems to be the default), inasmuch as my answer correctly displays text values without modification. – Scott Sep 25 '15 at 21:26

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .