Extract all instances of matching string in a range of cells by cell

  • Hello,


    I find myself stuck looking for a solution, which preferably would be in VBA to tie into the rest of the project.

    1. Variable number of rows (column E)
    2. For each cell, remove all characters unless the pattern is ###### (6 numbers)

    Note: The Qty may be anything >0.


    One of the obstacles is that a single cell may contain one or more pattern-matching strings (######).


    If more than one string per cell (thus far the most 'Seq#' per one cell was 11), then split with a line break - such as Chr(10).


    Three examples before vs. after below.


    Thank you,


    Stefan



    Before After
    Seq#: 123456 Qty: 15,165 123456
    Seq#: 456789 Qty: 285, Seq#: 345678 Qty: 14,534 456789
    345678
    Seq#: 123456 Qty: 15,165, Seq#: 786789 Qty: 6,285, Seq#: 345678 Qty: 14,534 123456
    456789
    345678
  • Go to Best Answer
  • Hello Stefan,


    Based on your explanations, would you agree that the third case should read :

    123456

    786789

    345678


    Thanks for your clarification

    If you feel like saying "Thank You" for the help received, do not hesitate to click the "Smiley" icon, below, in the bottom right corner :)

    • Best Answer

    Hello again,


    As long as you agree with the above message ... attached you will find your test file with a UDF to produce your results


    Hope this will help

  • Hello Carim,


    My apology for not replying sooner.


    You are absolutely correct with your correction in your first reply!


    I will take a look at your solution and will be back.


    Thank you for taking time to help me out!


    Stefan

  • Hello Stefan,


    No problem ... ;)


    Feel free to share your comments ...once you have tested the UDF

    If you feel like saying "Thank You" for the help received, do not hesitate to click the "Smiley" icon, below, in the bottom right corner :)

  • Excellent!


    This works like a charm.


    I’ll work on this some more Monday to include into the remainder of my procedure; i don't foresee any issues incorporating it there.


    Thank you again for your quick help and solution.


    Stefan

  • StefanG

    Selected a post as the best answer.
  • Glad to hear you could fix your problem :)

    If you feel like saying "Thank You" for the help received, do not hesitate to click the "Smiley" icon, below, in the bottom right corner :)

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!