+ Reply to Thread
Results 1 to 6 of 6

How to remove text from concatenated formula if cell is blank?

  1. #1
    Forum Contributor
    Join Date
    04-26-2013
    Location
    Orlando
    MS-Off Ver
    Excel 2016
    Posts
    191

    How to remove text from concatenated formula if cell is blank?

    Hi, I have the below forumal that separates text with "|". I would like to know how i can have the formula ignore blank cells so it skips the "|" seperator if the cell is empty.

    =INDIRECT("D"&ROW()-11)&" | "&INDIRECT("D"&ROW()-10)&" | "&INDIRECT("D"&ROW()-9)

    Sample with current formula: This is text from 11 rows above | This is text from 10 rows above | <-- I need to remove the last "|" separator because nothing is in the cell 9 rows above.

    TIA.

  2. #2
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,893

    Re: How to remove text from concatenated formula if cell is blank?

    Welcome to the forum

    Please attach a sample workbook (not a picture or pasted copy). Make sure there is just enough data to demonstrate your need. Include a BEFORE sheet and an AFTER sheet in the workbook if needed to show the process you're trying to complete or automate. Make sure your desired results are shown, mock them up manually if necessary.

    Remember to desensitize the data.

    Click on GO ADVANCED and then scroll down to Manage Attachments to open the upload window.
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  3. #3
    Forum Guru
    Join Date
    04-23-2012
    Location
    New Jersey, USA
    MS-Off Ver
    Excel 365
    Posts
    2,416

    Re: How to remove text from concatenated formula if cell is blank?

    I think you may be looking for something like this...
    Formula: copy to clipboard
    Please Login or Register  to view this content.

  4. #4
    Forum Contributor
    Join Date
    04-26-2013
    Location
    Orlando
    MS-Off Ver
    Excel 2016
    Posts
    191

    Re: How to remove text from concatenated formula if cell is blank?

    Quote Originally Posted by Rick Rothstein View Post
    I think you may be looking for something like this...
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    This works great but then i realized I would need a similar formula for a few other lines in the sheet that does almost the same thing. I thought maybe i can replicate your formula for the other lines but im not that good in excel

    I have attached the workbook sample.
    Attached Files Attached Files

  5. #5
    Forum Guru
    Join Date
    04-23-2012
    Location
    New Jersey, USA
    MS-Off Ver
    Excel 365
    Posts
    2,416

    Re: How to remove text from concatenated formula if cell is blank?

    I am completely clear on what you are doing in your sample, but I do have some comments which might help you in constructing your own formula.

    First, I do not see why you are using the INDIRECT function and subtracting numbers from the ROW() function. You know the cells where the data is located, so why not use it directly instead of INDIRECT'ing to them? So, instead of this...

    INDIRECT("B"&ROW()-11)

    from your formula, use this... B10 (and so forth for the other cells). That would make the formula I posted in Message #2 much easier to read...

    =REPLACE(IF(B10="",""," | "&B10)&IF(B11="",""," | "&B11)&IF(B12="",""," | "&B12),1,3,"")

    Notice the color three colored sections of code... except for the cell reference, they are identical. That is the key to the formula... just concatenate an identical section for each cell you want to examine (changing the cell referenced in that section, of course). Each colored section is looking at the cell to see if it is blank... if it is, that part of the formula output the empty text string ("") meaning nothing is added to the overall output from that section of the formula. However, if the cell is not blank, then your Space/VerticalLine/Space is concatenated onto the front of the cell reference. This happens for each colored section. So either nothing is outputted form that section or the Vertical Bar surrounded by spaces plus the text from the cell referenced in than section is outputted from that section. Now, once all the sections have been concatenated together, only one Vertical Bar will exist between the outputted text; however, there will be a Space/VerticalBar/Space located at the front of text concatenated together from each colored section, so I used the REPLACE function to remove the first three characters thus giving you the clean text output that you wanted.

  6. #6
    Forum Contributor
    Join Date
    04-26-2013
    Location
    Orlando
    MS-Off Ver
    Excel 2016
    Posts
    191

    Re: How to remove text from concatenated formula if cell is blank?

    Quote Originally Posted by Rick Rothstein View Post
    I am completely clear on what you are doing in your sample, but I do have some comments which might help you in constructing your own formula.

    First, I do not see why you are using the INDIRECT function and subtracting numbers from the ROW() function. You know the cells where the data is located, so why not use it directly instead of INDIRECT'ing to them? So, instead of this...

    INDIRECT("B"&ROW()-11)

    from your formula, use this... B10 (and so forth for the other cells). That would make the formula I posted in Message #2 much easier to read...

    =REPLACE(IF(B10="",""," | "&B10)&IF(B11="",""," | "&B11)&IF(B12="",""," | "&B12),1,3,"")

    Notice the color three colored sections of code... except for the cell reference, they are identical. That is the key to the formula... just concatenate an identical section for each cell you want to examine (changing the cell referenced in that section, of course). Each colored section is looking at the cell to see if it is blank... if it is, that part of the formula output the empty text string ("") meaning nothing is added to the overall output from that section of the formula. However, if the cell is not blank, then your Space/VerticalLine/Space is concatenated onto the front of the cell reference. This happens for each colored section. So either nothing is outputted form that section or the Vertical Bar surrounded by spaces plus the text from the cell referenced in than section is outputted from that section. Now, once all the sections have been concatenated together, only one Vertical Bar will exist between the outputted text; however, there will be a Space/VerticalBar/Space located at the front of text concatenated together from each colored section, so I used the REPLACE function to remove the first three characters thus giving you the clean text output that you wanted.
    As i just figured it out on my own i come back to see your other solution lol. Your absolutely right, it does make it easier. My document used direct references in the past but changed to the indirect formula, I don't remember why though. In my original document i have 4 of these stacked on top of each other. I think it may have been so i didnt have to keep updating the cell references but dont recall. Thanks a bunch for your help, i will be converting them to direct references.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Formula to remove 0 and let cell blank
    By vasc in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 05-28-2019, 04:24 AM
  2. [SOLVED] Date format for two dates in a concatenated formula text included in the formula?
    By bkanealy in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 01-12-2015, 04:33 PM
  3. [SOLVED] How to superscript concatenated text (formula) using VBA
    By meprad in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-09-2014, 06:37 AM
  4. remove dupes from concatenated text
    By dschoenfeld in forum Excel General
    Replies: 3
    Last Post: 04-03-2013, 06:19 PM
  5. Convert Concatenated Text to Formula
    By TristanRicAlindogan in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 01-13-2013, 12:38 AM
  6. Convert Concatenated Text to Formula
    By locyip in forum Excel General
    Replies: 7
    Last Post: 02-04-2010, 03:39 PM
  7. concatenated text to formula
    By Bill Elerding in forum Excel General
    Replies: 6
    Last Post: 05-04-2005, 09:06 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1