views:

9593

answers:

7

I need to return an empty cell from an Excel formula, but it appears that excel treats an empty string or a reference to an empty cell differently than a true empty cell. So essentially I want need something like

=IF(some_condition,EMPTY(),some_value)

I tried to do things such as

=IF(some_condition,"",some_value)

and

=IF(some_condition,,some_value)

and assuming B1 is an empty cell

=IF(some_condition,B1,some_value)

but none of these appear to be true empty cells, I'm guessing because they are the result of a formula. Is there any way to populate a cell if and only if some condition is met and otherwise keep the cell truly empty?

EDIT: as recommended I tried to return NA(), but for my purposes this did not work either. Is there a way to do this with VB?

EDIT: I am building a worksheet which pulls in data from other worksheets that is formatted to the very specific demands of an application which imports the data into a database. I do not have access to change the implementation of this application, and it fails if the value is "" instead of actually empty.

A: 

Try using the BLANK() worksheet function.

David M
A: 
=IF(ISBLANK(A1),"Blank",A1)
ozczecho
It seems that Bryan is not trying to test if the cell is empty, but rather make the cell containing formula empty. Which is IMHO not doable by definition - containing formula = not empty.
quosoo
+7  A: 

Excel does not have any way to do this.

The result of a formula in a cell in Excel must be a number, text, logical (boolean) or error. There is no formula cell value type of "empty" or "blank".

One practice that I have seen followed is to use NA() and ISNA(), but that may or may not really solve your issue since there is a big differrence in the way NA() is treated by other functions (SUM(NA()) is #N/A while SUM(A1) is 0 if A1 is empty).

Joe Erickson
+2  A: 

You're going to have to use VB, then. You'll iterate over the cells in your range, test the condition, and delete the contents if they match. Something like:

For Each cell in SomeRange
  if (cell.value = SomeTest) then cell.clearcontents

end
Boofus McGoofus
I would add to this: if you always have a particular range of cells you want to clear out the blank cells for, you could give that range a name, then modify Boofus' formula by changing SomeRange to Range("MyRange"). To set a name for your cells, select the cells, click Define Name on the Formulas tab of the ribbon, and enter "MyRange" in the Name field. (And of course you could replace MyRange with anything you want.)
DanM
I wound up using a slight modification to this solution. I then set it to be run before the file is saved and everything works wonderfully.
Bryan Ward
A: 

Try evaluating the cell using LEN. If it contains a formula LEN will return 0. If it contains text it will return greater than 0.

A: 

You can achieve what you want with a space between the speech marks. If the condition is true, it returns a space, which makes the cell appear empty, otherwise it return the FALSE value.

=IF(some_condition," ",some_value)

This worked for me!

Simon
No, this wouldn't have worked. I needed the cell actually empty, not just looking like it was empty. There is a big difference between empty and " ".
Bryan Ward