2014-02-04

Excel find first word without IFERROR() or IF(ISERROR())

In Excel, to find the first word in a cell, find the position of first space then return all characters up to but excluding the space: =LEFT(A1,FIND(" ",A1)-1).

The formula above fails with #VALUE if the string in A1 doesn't have a space or the cell is empty. A Excel 2007 solution is to wrap the entire formula in IFERROR to return a default value: =IFERROR(LEFT(A1,FIND(" ",A1)-1),A1). Excel 2003 doesn't have IFERROR, so the formula is much longer with the same formula for the condition and output of the IF formula: =IF(ISERROR(LEFT(A1,(FIND(" ",A1)))),A1,LEFT(A1,(FIND(" ",A1)-1))).

A shorter solution for Excel 2003 onwards is to append a space to the cell value in the FIND formula so that a default value can always be returned: =LEFT(A1,FIND(" ",A1&" ")-1). Note: Test if it works for OpenOffice Calc.

No comments:

Post a Comment