+ Reply to Thread
Results 1 to 37 of 37

Text in column D - Search for keywords, replace with GAP and place keyword in column E

  1. #1
    Registered User
    Join Date
    08-18-2020
    Location
    Valencia
    MS-Off Ver
    Mac excel - Office 365 - v 16.72
    Posts
    61

    Text in column D - Search for keywords, replace with GAP and place keyword in column E

    I have a text. I also have an array of keywords that appear in the that text.
    I need to search for those key words and when a match is found:
    a - Replace that keyword with the text GAP
    b - The keyword that was found will be placed in column E.

    The keywords must be in order that they occur in text.


    Text
    Yesterday, I went to Paul's house because he was ill. His mum was angry with me because I ate all the food in the fridge and I drank all the milk. I drove my car to the supermarket and I bought some bread and cheese and I took it back to the house. Paul's mum was happy when she saw the food.

    Words or expressions array
    went, was, ate, drank, drove, bought




    What I need to generate is

    COLUMN D
    Yesterday, I GAP to Paul's house because he GAP ill. His mum was angry with me because I GAP etc...
    Then those words need to appear in COLUMN E like so:
    went
    was
    ate
    drank
    drove
    bought

    Thanks

  2. #2
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,853

    Re: Text in column D - Search for keywords, replace with GAP and place keyword in column E

    This will require VBA. Shall I move the thread for you?
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

  3. #3
    Registered User
    Join Date
    08-18-2020
    Location
    Valencia
    MS-Off Ver
    Mac excel - Office 365 - v 16.72
    Posts
    61

    Re: Text in column D - Search for keywords, replace with GAP and place keyword in column E

    Oh wow. Yes, please.

  4. #4
    Forum Expert
    Join Date
    12-11-2011
    Location
    Netherlands
    MS-Off Ver
    office 365
    Posts
    3,293

    Re: Text in column D - Search for keywords, replace with GAP and place keyword in column E

    please upload a excel file
    Willem
    English is not my native language sorry for errors
    Please correct me if I'm completely wrong

  5. #5
    Forum Expert
    Join Date
    10-11-2021
    Location
    Netherlands
    MS-Off Ver
    365
    Posts
    1,386

    Re: Text in column D - Search for keywords, replace with GAP and place keyword in column E

    Here you go

    Please Login or Register  to view this content.
    Attached Files Attached Files

  6. #6
    Forum Expert
    Join Date
    10-11-2021
    Location
    Netherlands
    MS-Off Ver
    365
    Posts
    1,386

    Re: Text in column D - Search for keywords, replace with GAP and place keyword in column E

    Try this one instead, should work on a mac too.

    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    08-18-2020
    Location
    Valencia
    MS-Off Ver
    Mac excel - Office 365 - v 16.72
    Posts
    61

    Re: Text in column D - Search for keywords, replace with GAP and place keyword in column E

    I tried uploading the excel. Let's ee if you get it.
    Attached Files Attached Files

  8. #8
    Registered User
    Join Date
    08-18-2020
    Location
    Valencia
    MS-Off Ver
    Mac excel - Office 365 - v 16.72
    Posts
    61

    Re: Text in column D - Search for keywords, replace with GAP and place keyword in column E

    JEC - Hi - thanks but I downloaded the excel and it didn't work.

  9. #9
    Forum Expert
    Join Date
    10-11-2021
    Location
    Netherlands
    MS-Off Ver
    365
    Posts
    1,386

    Re: Text in column D - Search for keywords, replace with GAP and place keyword in column E

    Yes you have to replace the code in the file with the second code I gave you

  10. #10
    Registered User
    Join Date
    08-18-2020
    Location
    Valencia
    MS-Off Ver
    Mac excel - Office 365 - v 16.72
    Posts
    61

    Re: Text in column D - Search for keywords, replace with GAP and place keyword in column E

    Cannot run the macro "Map1.xlsm!jec". The macro may not be available in this workbook or all macros may be disabled.

    I get this error. But macros are enabled.

  11. #11
    Forum Expert
    Join Date
    10-11-2021
    Location
    Netherlands
    MS-Off Ver
    365
    Posts
    1,386

    Re: Text in column D - Search for keywords, replace with GAP and place keyword in column E

    The button is still assigned to the “old” macro. Reassign the new macro to the button or run it from the VBA editor.

  12. #12
    Registered User
    Join Date
    08-18-2020
    Location
    Valencia
    MS-Off Ver
    Mac excel - Office 365 - v 16.72
    Posts
    61

    Re: Text in column D - Search for keywords, replace with GAP and place keyword in column E

    Hi I have it working now but it is missing some functionality that I was looking for.
    Right now you have the array of answers in column E in order and a list BUT when I start I have the words in column C in unordered.
    I need the program to iterate through my "answers" in column C - match them in the text - replace with GAP and place them as the ordered answers in column E.

    It doesn't sound like much but if I have 30 answers then it is a pain and my always make mistakes - overlook a word now and again.

  13. #13
    Forum Expert
    Join Date
    10-11-2021
    Location
    Netherlands
    MS-Off Ver
    365
    Posts
    1,386

    Re: Text in column D - Search for keywords, replace with GAP and place keyword in column E

    Ok, how about

    Edit: forgot the gap. Code amended.

    Please Login or Register  to view this content.
    Last edited by JEC.; 05-06-2023 at 02:26 AM.

  14. #14
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,525

    Re: Text in column D - Search for keywords, replace with GAP and place keyword in column E

    Quote Originally Posted by codeBeast View Post
    What I need to generate is

    COLUMN D
    Yesterday, I GAP to Paul's house because he GAP ill. His mum was angry with me because I GAP etc...
    Then those words need to appear in COLUMN E like so:
    went
    was
    ate
    drank
    drove
    bought

    Thanks
    try
    Please Login or Register  to view this content.
    Last edited by jindon; 05-06-2023 at 02:24 AM. Reason: One line missed

  15. #15
    Registered User
    Join Date
    08-18-2020
    Location
    Valencia
    MS-Off Ver
    Mac excel - Office 365 - v 16.72
    Posts
    61

    Re: Text in column D - Search for keywords, replace with GAP and place keyword in column E

    Hi guys, I'm sure I'm doing something wrong. I get "Active X component can't create object".
    Is there any chance of you pasting this into the excel I uploaded. I seem to be missing a step.

  16. #16
    Forum Expert
    Join Date
    10-11-2021
    Location
    Netherlands
    MS-Off Ver
    365
    Posts
    1,386

    Re: Text in column D - Search for keywords, replace with GAP and place keyword in column E

    Ok, check the file
    Attached Files Attached Files
    Last edited by JEC.; 05-06-2023 at 02:25 AM.

  17. #17
    Registered User
    Join Date
    08-18-2020
    Location
    Valencia
    MS-Off Ver
    Mac excel - Office 365 - v 16.72
    Posts
    61

    Re: Text in column D - Search for keywords, replace with GAP and place keyword in column E

    Hi JEC - that generated went and was only in column E. The rest were not generated and still in the text.

  18. #18
    Forum Expert
    Join Date
    10-11-2021
    Location
    Netherlands
    MS-Off Ver
    365
    Posts
    1,386

    Re: Text in column D - Search for keywords, replace with GAP and place keyword in column E

    If I click the button, everything is generated as expected
    Last edited by JEC.; 05-06-2023 at 02:23 AM.

  19. #19
    Registered User
    Join Date
    08-18-2020
    Location
    Valencia
    MS-Off Ver
    Mac excel - Office 365 - v 16.72
    Posts
    61

    Re: Text in column D - Search for keywords, replace with GAP and place keyword in column E

    Let me close everything - redownload and test again.

  20. #20
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,525

    Re: Text in column D - Search for keywords, replace with GAP and place keyword in column E

    see the attached.
    Attached Files Attached Files

  21. #21
    Registered User
    Join Date
    08-18-2020
    Location
    Valencia
    MS-Off Ver
    Mac excel - Office 365 - v 16.72
    Posts
    61

    Re: Text in column D - Search for keywords, replace with GAP and place keyword in column E

    Jindon - this one worked for me.
    Thank you so much to Jindon, JEC and Popipipo.

    This will save me so much work. I think you're all great.

    Do I click anywhere to show my appreciation. I can't see any "click right answer" like in stackoverflow.

  22. #22
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,525

    Re: Text in column D - Search for keywords, replace with GAP and place keyword in column E

    You are welcome.

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED.

    Also, you may not be aware that you can thank those who have helped you by clicking the small star icon located in the lower left corner of the post in which the help was given. By doing so you can add to the reputation(s) of those who helped.

  23. #23
    Registered User
    Join Date
    08-18-2020
    Location
    Valencia
    MS-Off Ver
    Mac excel - Office 365 - v 16.72
    Posts
    61

    Re: Text in column D - Search for keywords, replace with GAP and place keyword in column E

    Oh - question. It works for the first text. I tried another text just below and clicked the run button but it does not work for the send text. I may have over a thousand texts here in the future. How do I apply the macro to the second text.

  24. #24
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,525

    Re: Text in column D - Search for keywords, replace with GAP and place keyword in column E

    Can you just upload a few example and the result that you want?

  25. #25
    Registered User
    Join Date
    08-18-2020
    Location
    Valencia
    MS-Off Ver
    Mac excel - Office 365 - v 16.72
    Posts
    61

    Re: Text in column D - Search for keywords, replace with GAP and place keyword in column E

    I think I'm going crazy - I can't find the upload icon.

  26. #26
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,525

    Re: Text in column D - Search for keywords, replace with GAP and place keyword in column E

    Please read the yellow banner at the top of this page on how to attach a file and a mocked up solution.

  27. #27
    Registered User
    Join Date
    08-18-2020
    Location
    Valencia
    MS-Off Ver
    Mac excel - Office 365 - v 16.72
    Posts
    61

    Re: Text in column D - Search for keywords, replace with GAP and place keyword in column E

    I hope I have enclosed the file.
    Attached Files Attached Files

  28. #28
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,525

    Re: Text in column D - Search for keywords, replace with GAP and place keyword in column E

    Assuming you have enough gap between data.
    Please Login or Register  to view this content.

  29. #29
    Registered User
    Join Date
    08-18-2020
    Location
    Valencia
    MS-Off Ver
    Mac excel - Office 365 - v 16.72
    Posts
    61

    Re: Text in column D - Search for keywords, replace with GAP and place keyword in column E

    I copied in and pasted the new code into the VBA module.
    I press the run button but only the first text and answers are generated.

  30. #30
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,525

    Re: Text in column D - Search for keywords, replace with GAP and place keyword in column E

    See the attached.
    Attached Files Attached Files

  31. #31
    Registered User
    Join Date
    08-18-2020
    Location
    Valencia
    MS-Off Ver
    Mac excel - Office 365 - v 16.72
    Posts
    61

    Re: Text in column D - Search for keywords, replace with GAP and place keyword in column E

    Amazing. Thank you.

  32. #32
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,525

    Re: Text in column D - Search for keywords, replace with GAP and place keyword in column E

    I've just noticed the order.

    If you want it to compare case sensitve
    change
    Please Login or Register  to view this content.
    to
    Please Login or Register  to view this content.
    so that "ever" comes before "In", otherwise it picks the position of "in" from "things"
    Last edited by jindon; 05-06-2023 at 03:44 AM.

  33. #33
    Registered User
    Join Date
    08-18-2020
    Location
    Valencia
    MS-Off Ver
    Mac excel - Office 365 - v 16.72
    Posts
    61

    Re: Text in column D - Search for keywords, replace with GAP and place keyword in column E

    Ah - Ok.
    I just changed code and noticed something else.

    It finds "ever" in everything. So we would need to tell the code that any word found needs to have a space before and after it ie: it's not "within" another string.

  34. #34
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,525

    Re: Text in column D - Search for keywords, replace with GAP and place keyword in column E

    In that case...
    Please Login or Register  to view this content.
    This is Case Sensitive, if you want it to non case sensitive then change 0 to 1
    Please Login or Register  to view this content.
    to
    Please Login or Register  to view this content.
    Attached Files Attached Files

  35. #35
    Registered User
    Join Date
    08-18-2020
    Location
    Valencia
    MS-Off Ver
    Mac excel - Office 365 - v 16.72
    Posts
    61

    Re: Text in column D - Search for keywords, replace with GAP and place keyword in column E

    That's amazing but now I noticed that it finds each word multiple times. It must only find the first occurence then stop searching. Sorry!!!

  36. #36
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,525

    Re: Text in column D - Search for keywords, replace with GAP and place keyword in column E

    So only first appeared match?
    Please Login or Register  to view this content.
    to
    Please Login or Register  to view this content.
    Attached Files Attached Files

  37. #37
    Registered User
    Join Date
    08-18-2020
    Location
    Valencia
    MS-Off Ver
    Mac excel - Office 365 - v 16.72
    Posts
    61

    Re: Text in column D - Search for keywords, replace with GAP and place keyword in column E

    That is brilliant. I'm really sorry that I wasn't as specific as I should have been. I will really try and be more detailed in my requirements next time.
    Thanks - it helped so much. That code is way over my head, but when I read it, I am learning all the time.

+ 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. Searching for multiple keywords in multiple sources of text
    By Bart.. in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 01-12-2022, 10:33 AM
  2. Replies: 4
    Last Post: 07-24-2020, 10:23 AM
  3. Search cells C1:C3000 for keyword and if exists place a keyword in A1:A3000
    By GregQuick in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 11-24-2015, 07:38 PM
  4. Replies: 4
    Last Post: 12-16-2013, 06:29 PM
  5. Replies: 1
    Last Post: 04-23-2012, 04:23 AM
  6. Column keyword search using list of keywords
    By tshrader in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-28-2011, 03:46 PM
  7. Replies: 1
    Last Post: 12-27-2010, 08:53 AM

Tags for this Thread

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