+ Reply to Thread
Results 1 to 9 of 9

Extracting and adding text

Hybrid View

  1. #1
    Registered User
    Join Date
    02-16-2025
    Location
    Arkansas, USA
    MS-Off Ver
    Office 365
    Posts
    4

    Extracting and adding text

    Long time lurker for information and first time poster.

    Been getting more involved in Excel the past few years and am nowhere near extremely proficient with it yet, but have been beating my head against the wall on this and I'm sure I'm overcomplicating it. I've inherited a data set used for tracking production on an industrial construction sit from a previous employee of the company I work for. We're given a cable ID tag which I'd like to strip down to it's individual Input/Output (I/O) identifier for tracking purposes. I've attached a small excerpt from the data for reference along with the text I'd like it to display in column I. What's currently being displayed is in column H. The instruments have letter identifiers that are two to three characters followed by 3-5 numbers for the device number. Everything I've done so far has had to have me adjust for devices with only two letters or with more than 3 numbers and I know there has to be a better way of doing this to save me time with 2,000+ lines.

    Any help is very very much appreciated and I'm looking forward to developing my skills more in this community.
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    04-14-2009
    Location
    Taiwan
    MS-Off Ver
    Excel 2016,2019,O365
    Posts
    2,924

    Re: Extracting and adding text

    One way,
    =LET(
      a,FILTER(H2:H100,H2:H100<>""),
      DROP(REDUCE("",a,LAMBDA(x,y,VSTACK(x,
       LET(
         b,MIN(IFERROR(SEARCH(SEQUENCE(10,,0),y),100)),
         c,TEXTBEFORE(y,"-"),
         LEFT(c,b-1)&"-"&MID(c,b,10)
       )
     ))),1)
    )
    Attached Files Attached Files

  3. #3
    Registered User
    Join Date
    02-16-2025
    Location
    Arkansas, USA
    MS-Off Ver
    Office 365
    Posts
    4

    Re: Extracting and adding text

    Quote Originally Posted by windknife View Post
    One way,
    =LET(
      a,FILTER(H2:H100,H2:H100<>""),
      DROP(REDUCE("",a,LAMBDA(x,y,VSTACK(x,
       LET(
         b,MIN(IFERROR(SEARCH(SEQUENCE(10,,0),y),100)),
         c,TEXTBEFORE(y,"-"),
         LEFT(c,b-1)&"-"&MID(c,b,10)
       )
     ))),1)
    )
    Thanks for the great work! Trying to understand the work you've done and I see you used H column. Would this be the same if you used the cable id column A instead? Sorry if this is a bumd question. Just trying to learn and never done anything to this degree.

  4. #4
    Forum Expert
    Join Date
    04-14-2009
    Location
    Taiwan
    MS-Off Ver
    Excel 2016,2019,O365
    Posts
    2,924

    Re: Extracting and adding text

    If you want to use column A instead of column H, try this.
    =LET(
      a,TEXTAFTER(FILTER(A2:A100,A2:A100<>""),"-"),
      DROP(REDUCE("",a,LAMBDA(x,y,VSTACK(x,
       LET(
         b,MIN(IFERROR(SEARCH(SEQUENCE(10,,0),y),100)),
         c,TEXTBEFORE(y,"-"),
         LEFT(c,b-1)&"-"&MID(c,b,10)
       )
     ))),1)
    )

  5. #5
    Registered User
    Join Date
    02-16-2025
    Location
    Arkansas, USA
    MS-Off Ver
    Office 365
    Posts
    4

    Re: Extracting and adding text

    Quote Originally Posted by alansidman View Post
    An alternative solution using Power Query

    let
        Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
        #"Inserted Text Before Delimiter" = Table.AddColumn(Source, "Text Before Delimiter", each Text.BeforeDelimiter([#"I/O"], "-"), type text),
        #"Split Column by Character Transition" = Table.SplitColumn(#"Inserted Text Before Delimiter", "Text Before Delimiter", Splitter.SplitTextByCharacterTransition((c) => not List.Contains({"0".."9"}, c), {"0".."9"}), {"Text Before Delimiter.1", "Text Before Delimiter.2"}),
        #"Merged Columns" = Table.CombineColumns(#"Split Column by Character Transition",{"Text Before Delimiter.1", "Text Before Delimiter.2"},Combiner.CombineTextByDelimiter("-", QuoteStyle.None),"I/O New")
    in
        #"Merged Columns"
    Quote Originally Posted by windknife View Post
    If you want to use column A instead of column H, try this.
    =LET(
      a,TEXTAFTER(FILTER(A2:A100,A2:A100<>""),"-"),
      DROP(REDUCE("",a,LAMBDA(x,y,VSTACK(x,
       LET(
         b,MIN(IFERROR(SEARCH(SEQUENCE(10,,0),y),100)),
         c,TEXTBEFORE(y,"-"),
         LEFT(c,b-1)&"-"&MID(c,b,10)
       )
     ))),1)
    )
    Thank you both for your help. I'm getting a #N/A error when trying to import the work into my data set. My time is limited so I'm going to have to hand do it until I get enough time to learn and understand these operations better. Thank you again!

  6. #6
    Registered User
    Join Date
    02-16-2025
    Location
    Arkansas, USA
    MS-Off Ver
    Office 365
    Posts
    4

    Re: Extracting and adding text

    Quote Originally Posted by windknife View Post
    If you want to use column A instead of column H, try this.
    =LET(
      a,TEXTAFTER(FILTER(A2:A100,A2:A100<>""),"-"),
      DROP(REDUCE("",a,LAMBDA(x,y,VSTACK(x,
       LET(
         b,MIN(IFERROR(SEARCH(SEQUENCE(10,,0),y),100)),
         c,TEXTBEFORE(y,"-"),
         LEFT(c,b-1)&"-"&MID(c,b,10)
       )
     ))),1)
    )
    Windknife,

    I've had time to work through this and try to troubleshoot it but I still cant get it to work correctly. Do you have any ideas why I might be getting a #N/A error?

  7. #7
    Forum Expert
    Join Date
    04-14-2009
    Location
    Taiwan
    MS-Off Ver
    Excel 2016,2019,O365
    Posts
    2,924

    Re: Extracting and adding text

    Upload a sample file with error message.

  8. #8
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 insider Version 2505 Win 11
    Posts
    24,729

    Re: Extracting and adding text

    An alternative solution using Power Query

    let
        Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
        #"Inserted Text Before Delimiter" = Table.AddColumn(Source, "Text Before Delimiter", each Text.BeforeDelimiter([#"I/O"], "-"), type text),
        #"Split Column by Character Transition" = Table.SplitColumn(#"Inserted Text Before Delimiter", "Text Before Delimiter", Splitter.SplitTextByCharacterTransition((c) => not List.Contains({"0".."9"}, c), {"0".."9"}), {"Text Before Delimiter.1", "Text Before Delimiter.2"}),
        #"Merged Columns" = Table.CombineColumns(#"Split Column by Character Transition",{"Text Before Delimiter.1", "Text Before Delimiter.2"},Combiner.CombineTextByDelimiter("-", QuoteStyle.None),"I/O New")
    in
        #"Merged Columns"
    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

  9. #9
    Registered User
    Join Date
    12-23-2012
    Location
    Macksville, Australia
    MS-Off Ver
    Excel 365
    Posts
    9

    Re: Extracting and adding text

    If you have the new REGEX functions then the formula can become much simpler (or at least much shorter).
    Formula: copy to clipboard
    =REGEXREPLACE(A2:A7,"(.+\-)(\D+)(\d+)(.+)","\2-\3")


    If that table of data is a formal Excel table and the results are to be in a column in that table then the formula would become as below
    (except replace the # symbol with an 'at' symbol that the forum software will not allow me to post at this stage )
    Formula: copy to clipboard
    =REGEXREPLACE([#[CABLE ID]],"(.+\-)(\D+)(\d+)(.+)","\2-\3")
    Attached Files Attached Files
    Last edited by Peter_SSs; 03-09-2025 at 07:18 AM.
    Hope this helps, good luck.
    Peter

+ 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. Extracting the Year from a Date then adding 5 years
    By tonimarie797 in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 08-24-2021, 10:04 PM
  2. Extracting multiple results and adding them in separate columns
    By Wizards in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 11-11-2019, 02:40 AM
  3. Adding datemodified to .PDF file extracting macro
    By Chandrahaas in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-03-2014, 05:21 AM
  4. Extracting numbers and text from inconsistent text/number formatted string
    By Brandivil in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 01-25-2013, 01:46 PM
  5. [SOLVED] extracting numbers from text string and adding them together
    By Leif Magnus in forum Excel Formulas & Functions
    Replies: 15
    Last Post: 12-04-2012, 01:31 PM
  6. Excel 2007 : Extracting and adding numbers
    By Brian.gronski in forum Excel General
    Replies: 6
    Last Post: 03-10-2011, 10:13 AM
  7. extracting and adding numbers
    By cj in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 02-12-2006, 07:45 AM

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