Consulting

Results 1 to 17 of 17

Thread: Find and collate rows with repeated partial text in one column

  1. #1

    Find and collate rows with repeated partial text in one column

    I'm working on analysing one data worksheet which has over 6200 rows (no blanks) within 7 columns (A:G).


    ColD has the main data fields which are the focus of this question.


    I need to find EVERY repeated THREE WORDS in all ColD cells, highlight them in red, and collate the entire data rows of those cells in groups separated with one blank row in another worksheet.


    I have manually created the attached example, hoping it would illustrate my question properly.


    I do appreciate any precious assistance with this question.


    Many thanks in advance.

    sample_data_example.xlsx

  2. #2
    VBAX Mentor 大灰狼1976's Avatar
    Joined
    Dec 2018
    Location
    SuZhou China
    Posts
    470
    Location
    Hi mpeterson!
    Please refer to the attachment.
    The result is output at Sheet3.
    Attached Files Attached Files

  3. #3
    Hi SuZhou,
    I really don't know how to thank you for such masterpiece code you produced. It ran smoothly with no problem and yielded the desired results.
    I published this question a while ago and over 100 expert read it, but no one was able to even suggest a solution, rather to produce it as you did. Thus, I do appreciate your time, effort and knowledge you used to code the solution.
    Once again thank you very much, and I'm sure you do have a great value to add to this world SuZhou.
    All the best.

    M.

  4. #4
    VBAX Mentor 大灰狼1976's Avatar
    Joined
    Dec 2018
    Location
    SuZhou China
    Posts
    470
    Location
    Because there are continuous spaces in many cells, so there will be deviations in starting position and length when marking color. It would be better if we could standardize the D column data.
    In addition, the processing speed is slower when data are many. I will make a better sample today.

  5. #5
    VBAX Mentor 大灰狼1976's Avatar
    Joined
    Dec 2018
    Location
    SuZhou China
    Posts
    470
    Location
    There is little difference in speed. because of it takes a lot of time to mark colors.
    Attached Files Attached Files

  6. #6
    Thank you very much SuZhou for your modification. In fact, I noticed differences in text red highlight it in the first code, but said to myself I will do it manually. For you to perfect it in such way, is considered remarkable.

    Well, I ran the new code on my sample text, and it ran PERFECT 100% as expected.

    But, when I ran it on the real data, it halted on this line:
    rng.Cells(i, 4).Characters(Start:=arr1((i - 1) * 3 + 1), Length:=arr1((i - 1) * 3 + 2)).Font.Color = vbRed
    with runtime error '9' Subscript out of range. In my real ColD data there are cells with over 250 chars.

    I also tried to normalize ColD data with the other new code, some cell were deleted with #VALUE! string instead of the original string. I realised they are those cells which are longer than 250 chars.

    Can you please apply some modification to accommodate for longer text?

    Please accept my deep gratitude.

    M.

  7. #7
    VBAX Mentor 大灰狼1976's Avatar
    Joined
    Dec 2018
    Location
    SuZhou China
    Posts
    470
    Location
    Can you send me a wrong form? Just the wrong part is enough. I will find out the problem.

  8. #8
    VBAX Mentor 大灰狼1976's Avatar
    Joined
    Dec 2018
    Location
    SuZhou China
    Posts
    470
    Location
    Confirmed results:
    1. Application.Trim() will make errors when it is over 255 characters long. But it can be implemented in other ways.
    2. Characters(Start:=?, Length:=?).Font.Color when more than 255 characters long is no problem.
    so I need 2.'s wrong texts.

  9. #9
    VBAX Mentor 大灰狼1976's Avatar
    Joined
    Dec 2018
    Location
    SuZhou China
    Posts
    470
    Location
    Solution of Standardize D column data:
    Private Sub CommandButton3_Click()
    Dim i&
    For i = 1 To 10    'It is assumed that there are no more than 10 consecutive spaces.
      Columns(4).Replace "  ", " "
    Next i
    For i = 1 To [d65536].End(3).Row
      If Left(Cells(i, 4), 1) = " " Then Cells(i, 4) = Mid(Cells(i, 4), 2)
      If Right(Cells(i, 4), 1) = " " Then Cells(i, 4) = Left(Cells(i, 4), Len(Cells(i, 4)) - 1)
    Next i
    End Sub

  10. #10
    Dear SuZhou, IT WORKED, IT WORKED ..

    In fact, it was my mistake. I copied 150 cells from real data in ColD and pasted it in your updated second file sample in ColD. I did not fill out other columns A-C and E-F with fake "data". This is why the code halted. As soon as I realised it, I filled those empty cells and ran your genius code again, and IT WORKED AS NEVER BEFORE.

    I really don't know what to say, you left me speechless. But I still can say "Thank you very much my dear SuZhou, wishing for you all the best at present and future".

    M.

  11. #11
    May I ask for one more thing please ..
    Is it possible to copy only the red text in ColD to ColG?
    That's it .. no more questions .. : )

    M.

  12. #12
    VBAX Mentor 大灰狼1976's Avatar
    Joined
    Dec 2018
    Location
    SuZhou China
    Posts
    470
    Location
    Hi mpeterson! Don't mention it.
    I'll settle it tomorrow.

  13. #13
    VBAX Mentor 大灰狼1976's Avatar
    Joined
    Dec 2018
    Location
    SuZhou China
    Posts
    470
    Location
    Hi mpeterson!
    I want to confirm output to which worksheet's G column.

  14. #14
    Hi SuZhou,

    Sure .. I think I typed G instead of H as ColG has data already in it. I'm attaching the same sample file with the desired results in ColH, which will be used in a more detailed analysis.
    Thank you very much indeed SuZhou.

    M.
    Attached Files Attached Files

  15. #15
    VBAX Mentor 大灰狼1976's Avatar
    Joined
    Dec 2018
    Location
    SuZhou China
    Posts
    470
    Location
    Hi mpeterson!
    Please refer to the attachment.
    have a good weekend
    Attached Files Attached Files

  16. #16
    Great .. really great SuZhou .. you really stunned me. I really wish for you all success that deserves your knowledge, experience and above all .. sincerety ..
    Thank you very much my dear ..

    M.

  17. #17

Posting Permissions

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