+ Reply to Thread
Results 1 to 26 of 26

Find keyword and delete the rows below and above

  1. #1
    Registered User
    Join Date
    09-05-2012
    Location
    Türkiye
    MS-Off Ver
    Excel 2013
    Posts
    80

    Find keyword and delete the rows below and above

    my request was changed as in 7th post
    first part:
    firts I want to find a specific word and the delete the rows above the row including found keyword.
    In the sample find "there is no guarentee" then delete the rows (row numbers:4-3-2-1) (there is "there is no guarentee" 2 TIMES BUT THE FIRST ONE)

    second part

    I want to find a specific word and the delete the rows BELOW the row including found keyword.
    In the sample find "ringtone to your cell" then delete the rows (row numbers:35-36-37...)) (there is "ringtone to your cell" 2 TIMES BUT THE LAST ONE)

    This macro should work for all sheet in workbook.

    before.xlsx
    after.xlsx
    Last edited by zeroist; 09-11-2013 at 03:16 AM.

  2. #2
    Forum Expert
    Join Date
    07-15-2012
    Location
    Leghorn, Italy
    MS-Off Ver
    Excel 2010
    Posts
    3,431

    Re: Find keyword and delete the rows below and above

    ther'is only one row with the selected keyword in one sheet ?
    If solved remember to mark Thread as solved

  3. #3
    Registered User
    Join Date
    09-05-2012
    Location
    Türkiye
    MS-Off Ver
    Excel 2013
    Posts
    80

    Re: Find keyword and delete the rows below and above

    Yes There is only one keyword.And I want to delete the rows below and above.
    in the sample after applying macro I should only have the rows between 6 and 33(after macro it should be like that after macro.xlsx
    Quote Originally Posted by patel45 View Post
    ther'is only one row with the selected keyword in one sheet ?

  4. #4
    Forum Expert
    Join Date
    07-15-2012
    Location
    Leghorn, Italy
    MS-Off Ver
    Excel 2010
    Posts
    3,431

    Re: Find keyword and delete the rows below and above

    I'm finding "ringtone to your cell" 2 times in each sheet, you marked in red only the second
    Last edited by patel45; 09-10-2013 at 02:49 AM.

  5. #5
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: Find keyword and delete the rows below and above

    Hi, patel45,

    are you playing games with the TO?
    ther'is only one row with the selected keyword in one sheet ?
    I'm finding "ringtone to your cell" 2 times in each sheet, you marked in red only the second
    Can´t find any code or hint for a solution in your answers in this thread so far.

    Ciao,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

  6. #6
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: Find keyword and delete the rows below and above

    Hi, zeroist,

    I used two codes in my attempt to solve your problem. The first features the items you will search for as well as the number of rows to delete above and/or below the found item and a boolean to decide whether to delete or "paint" the area (we could add another parameter for the colour but I choose yellow here).

    Please Login or Register  to view this content.
    The second will loop through all worksheets and do accordingly:
    Please Login or Register  to view this content.
    Ciao,
    Holger

  7. #7
    Registered User
    Join Date
    09-05-2012
    Location
    Türkiye
    MS-Off Ver
    Excel 2013
    Posts
    80

    Re: Find keyword and delete the rows below and above

    Thank you HaHoBe.
    I am really sorry.you are right there is " ringtone to your cell " 2 times.ok.let me change the statu.

    firts I want to find a specific word(there might be more than one.The answer of which one to choose is (the indicator) the FIrst OR the LAST ONE IN THE ROW)
    first part:
    firts I want to find a specific word and the delete the rows above the row including found keyword.
    In the sample find "there is no guarentee" then delete the rows (row numbers:4-3-2-1) (there is "there is no guarentee" 2 TIMES BUT THE FIRST ONE)

    second part

    I want to find a specific word and the delete the rows BELOW the row including found keyword.
    In the sample find "ringtone to your cell" then delete the rows (row numbers:35-36-37...)) (there is "ringtone to your cell" 2 TIMES BUT THE LAST ONE)

    This macro should work for all sheet in workbook.

    before.xlsx
    after.xlsx
    Last edited by zeroist; 09-10-2013 at 09:48 AM.

  8. #8
    Registered User
    Join Date
    09-05-2012
    Location
    Türkiye
    MS-Off Ver
    Excel 2013
    Posts
    80

    Re: Find keyword and delete the rows below and above

    not yet any progress?

  9. #9
    Registered User
    Join Date
    09-05-2012
    Location
    Türkiye
    MS-Off Ver
    Excel 2013
    Posts
    80

    Re: Find keyword and delete the rows below and above

    please help ASAP

  10. #10
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: Find keyword and delete the rows below and above

    Hi, zeroist,

    maybe your description is good for you to understand but I´m having problems understanding why in the After workbook Row 12 still shows the item which should have been deleted according to your requirements as I understand them. Before investing more time I would like you to clarify on that and assure that no further change in requirements will come.

    A word an ASAP: everybody here in the forum is helping out for free, so any help available can only come if time is on hand for the preson who wants to help and if the problem is laid down clear to understand. If you really are in need of a solution you should consider to use the Commercial Services here but I´m afraid even there you would need to clarify what I asked above (I can assure you that I won´t take care of your thread over there if you decide to do so).

    Ciao,
    Holger

  11. #11
    Registered User
    Join Date
    09-05-2012
    Location
    Türkiye
    MS-Off Ver
    Excel 2013
    Posts
    80

    Re: Find keyword and delete the rows below and above

    I am sorry for my english.I am trying to do my best for my english.
    Row 12 still exist because I am only interested in first keyword (keyword in row is:"there is no guarentee") which is in row 5.

    http://sketchtoy.com/49962974

  12. #12
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: Find keyword and delete the rows below and above

    Hi, zeroist,

    maybe this code will perform as you wish:

    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    Ciao,
    Holger

  13. #13
    Registered User
    Join Date
    09-05-2012
    Location
    Türkiye
    MS-Off Ver
    Excel 2013
    Posts
    80

    Re: Find keyword and delete the rows below and above

    I tried to test it but it seems there is something missed

  14. #14
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: Find keyword and delete the rows below and above

    Hi, zeroist,

    could you be a bit more specific about what I might have missed than just to state something without saying exactly what? When I tested the code on a copied sheet from your Before-workbook the code did exactly what I understood it should do.

    You would need to start with EF953570_3 and maybe adjust the parameters which are passed due to the explanation (I entered them from what I read in your latest posts as well what I saw in the demo).

    Ciao,
    Holger

  15. #15
    Registered User
    Join Date
    09-05-2012
    Location
    Türkiye
    MS-Off Ver
    Excel 2013
    Posts
    80

    Re: Find keyword and delete the rows below and above

    Hi HaHoBe
    I am posting the pics about errors...


    1.jpg
    2.jpg

  16. #16
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: Find keyword and delete the rows below and above

    Hi, zeroist,

    although I separated the two procedures when posting here they should be included into either one or 2 standard modules in the very same workbook for the ease of use (I had my versions of the code in the same modules).

    Ciao,
    Holger

  17. #17
    Registered User
    Join Date
    09-05-2012
    Location
    Türkiye
    MS-Off Ver
    Excel 2013
    Posts
    80

    Re: Find keyword and delete the rows below and above

    Hi HaHoBe

    Here what happens after macro after2.xlsx

    not deleting the rows totally both at above and below part

  18. #18
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: Find keyword and delete the rows below and above

    Hi, zeroist,

    maybe the best idea that you have missed up till now: make a copy of one sheet, mark the items to find and not to delete in one color (only the characters, say blue), the ones to delete in a different one (characters, red) and the areas to delete in a third colour (range/cells in yellow) and upload that workbook. Then maybe it will be clear to me what is wrong with what I coded from what I understood from your posts.

    Ciao,
    Holger

  19. #19
    Registered User
    Join Date
    09-05-2012
    Location
    Türkiye
    MS-Off Ver
    Excel 2013
    Posts
    80

    Re: Find keyword and delete the rows below and above

    Hi HaHoBe,

    I hope this pic helps... process.jpg

  20. #20
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: Find keyword and delete the rows below and above

    Hi, zeroist,

    due to constellation you will have to search for ringtone to your cell first as on the start there are 2 occurrances but afterwards there is only one as the first one will have been deleted by the first occurrance of there is no guarentee.

    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    Ciao,
    Holger

  21. #21
    Registered User
    Join Date
    09-05-2012
    Location
    Türkiye
    MS-Off Ver
    Excel 2013
    Posts
    80

    Re: Find keyword and delete the rows below and above

    I dont know how to thank you.It is done.

  22. #22
    Registered User
    Join Date
    09-05-2012
    Location
    Türkiye
    MS-Off Ver
    Excel 2013
    Posts
    80

    Re: Find keyword and delete the rows below and above

    I need one more help.In another sample it gave error as "runtime error '1004'. methot 'range' of object '_worksheet' failed.here is sample second.xlsx

  23. #23
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: Find keyword and delete the rows below and above

    Hi, zeroist,

    if the keywords aren´t found on the sheet that´s the normal way with teh code as it was supplied. Just change the position of the If-Statement that raisees the error, and the code will run through nicely (well, at least not raising any errors on testing):

    The calling procedure will remain unchanged and just get a higher version number
    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    Ciao,
    Holger

  24. #24
    Registered User
    Join Date
    09-05-2012
    Location
    Türkiye
    MS-Off Ver
    Excel 2013
    Posts
    80

    Re: Find keyword and delete the rows below and above

    Hi HaHoBe,
    I know you are getting angry with me,but one more help,

    if the keyword is not found (even one of the keywords is not found), can we delete the page from workbook.

    in the sample delete page4. second.xlsx

  25. #25
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: Find keyword and delete the rows below and above

    Hi, zeroist,

    I know you are getting angry with me,but one more help,
    I prefer to answer to threads where the original request remains the same throughout as the concept was developed on hte first post (which is reverted withthe last request).

    This is the code for the whole module in one code block:
    Please Login or Register  to view this content.
    Ciao,
    Holger

  26. #26
    Registered User
    Join Date
    09-05-2012
    Location
    Türkiye
    MS-Off Ver
    Excel 2013
    Posts
    80

    Re: Find keyword and delete the rows below and above

    you are great HaHoBe.Thanks for the one code block.

+ 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. Replies: 6
    Last Post: 03-18-2014, 11:16 AM
  2. Macro To Find & Copy Rows Based On A Keyword List
    By Lilfish in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-02-2013, 10:02 AM
  3. Replies: 4
    Last Post: 09-18-2012, 10:54 AM
  4. Replies: 2
    Last Post: 07-13-2012, 04:02 AM
  5. VBA Popup to search a sheet and delete rows based on keyword entered
    By MichaelJG in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 06-05-2011, 08:08 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