In MS Excel the ISTEXT function can be used to check for a text value in a cell. When applied to a single cell this function will return “True” or “False” based on whether or not there is a value (any value) in the desired cell.
Example: the formula below will return “True” if there is any value in cell A1, otherwise “False” will be returned. =ISTEXT (A1) Very recently I came across a situation where using the ISTEXT function within a formula allowed me to perform a given task efficiently and with much higher precision. Consider the table below as an example:
The task I want to perform here is to concatenate the values in each row into a single cell. In other words, I want to take the values is cells A, B, C, D, and E for each given row and concatenate them into one single cell. I am also required to have a underscore (_) between the joining cells (i.e. Cells A through E). Doing so is rather simple. All I have to do is to insert the formula below in a cell (cell G2 in this case) and apply the formula to the full range by dragging it down.:
=A2&"_"&B2&"_"&C2&"_"&D2&"_"&E2 NOTE] The following formula could also be used as an equivalent substitute for the formula above =CONCATENATE(A2,"_",B2,"_",C2,"_",D2,"_",E2) Here is the outcome after applying either one of these two formulas:
While it may seem that the formula above has delivered the desired results, there is one flaw that this formula could not address: extra Underscores!. To get a better idea have a look at the values for fields C through E. Not all the cells in this range have a value and the blank cells (located in columns D and E) are detrimental as they result in additional and unwanted underscores at the end of the string concatenation (see cells G3, G6, G7, G9, and G11).
The traditional way to suppress these unwanted underscores is by manually altering the formula for those rows that contain blank values. Doing so may be rather simple in the example that I provided, however; imagine if we were dealing with hundreds, thousands or even more records. In such situations altering select formulas would become rather time consuming and daunting.
By utilizing the “ISTEXT” function we could arrive at the desired results with no additional underscores without needing to alter formulas for select cells. Here is how to do this: I will insert the formula below, which contains embedded ISTEXT statements, in cell G2 and then I will drag it down to cover the entire range: =A2&"_"&B2&"_"&C2&IF(ISTEXT(D2),"_"&D2,"")&IF(ISTEXT(E2),"_"&E2,"") Here is the end result:
As could be observed, using this formula has suppressed all unwanted underscores and most importantly eliminated the need for manually customizing the formulas for those rows that have blank cells. AMAZING!
0 Comments
Leave a Reply. 
CategoriesArchives
February 2020
