+ Reply to Thread
Results 1 to 16 of 16

Delete Specific Row up to a certain word

  1. #1
    Registered User
    Join Date
    05-09-2013
    Location
    New York, NY
    MS-Off Ver
    Excel 2003
    Posts
    7

    Delete Specific Row up to a certain word

    Need Help: Need VBA Code to Delete rows B5 to specific word for various worksheets.

    Thanks
    Jesse

  2. #2
    Forum Expert NeedForExcel's Avatar
    Join Date
    03-16-2013
    Location
    Pune, India
    MS-Off Ver
    Excel 2016:2019, MS 365
    Posts
    3,873

    Re: Delete Specific Row up to a certain word

    Too less information to understand. Please clarify more what you exactly want the Macro to do?
    Cheers!
    Deep Dave

  3. #3
    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: Delete Specific Row up to a certain word

    Hi, jesse77581,

    maybe this shows a way how to proceed:
    Please Login or Register  to view this content.
    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

  4. #4
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,528

    Re: Delete Specific Row up to a certain word

    jesse77581
    You could try this on a copy of your workbook.


    Please Login or Register  to view this content.
    Last edited by jolivanes; 05-10-2013 at 01:45 AM. Reason: Changed range

  5. #5
    Registered User
    Join Date
    05-09-2013
    Location
    New York, NY
    MS-Off Ver
    Excel 2003
    Posts
    7

    Re: Delete Specific Row up to a certain word

    This code worked below BUT need to keep the word"Test"

    Sub EF921892()
    Dim rngFound As Range
    Set rngFound = Range("B:B").Find(what:="Test")
    If Not rngFound Is Nothing Then
    Range(Range("B5"), rngFound).EntireRow.Delete
    End If
    End Sub

  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: Delete Specific Row up to a certain word

    Hi, jesse77581,

    please use code-tags when you post a procedure.

    Please Login or Register  to view this content.
    This will delete all rows between row 5 and the row above the found word.

    Ciao,
    Holger

  7. #7
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,528

    Re: Delete Specific Row up to a certain word

    Maybe a mock-up attachment with before and after will help.

  8. #8
    Registered User
    Join Date
    05-09-2013
    Location
    New York, NY
    MS-Off Ver
    Excel 2003
    Posts
    7

    Re: Delete Specific Row up to a certain word

    How do I add in the code below various worksheets names with the same word "test" that needs to be deleted on those sheets?


    Sub EF921892()
    Dim rngFound As Range
    Set rngFound = Range("B:B").Find(what:="Test")
    If Not rngFound Is Nothing Then
    Range(Range("B5"), rngFound.Offset(-1, 0)).EntireRow.Delete
    End If
    End Sub

    Thank You Very Much
    Jesse

  9. #9
    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: Delete Specific Row up to a certain word

    Hi, jesse77581,

    please use code-tags when posting procedures.

    You are short on explaining what various sheets means: in all sheets or in selected sheets?
    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    Ciao,
    Holger

  10. #10
    Registered User
    Join Date
    05-09-2013
    Location
    New York, NY
    MS-Off Ver
    Excel 2003
    Posts
    7

    Re: Delete Specific Row up to a certain word

    Holger - Thats exactly what i needed. Thanks im going to try to understand this code.

    Jesse

  11. #11
    Registered User
    Join Date
    05-09-2013
    Location
    New York, NY
    MS-Off Ver
    Excel 2003
    Posts
    7

    Re: Delete Specific Row up to a certain word

    Lets say if i accidentally ran the Macro again, how do i stop it from deleting the rows above B1:B5, leaving the word test? Thanks..

  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: Delete Specific Row up to a certain word

    Hi, Jesse,

    add a check to the row of the found item like
    Please Login or Register  to view this content.
    Ciao,
    Holger

  13. #13
    Registered User
    Join Date
    05-09-2013
    Location
    New York, NY
    MS-Off Ver
    Excel 2003
    Posts
    7

    Re: Delete Specific Row up to a certain word

    got it thanks Holger. Do you recommend any tutorials for learning vba?

  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: Delete Specific Row up to a certain word

    Hi, Jesse,

    maybe start with looking at http://www.excelforum.com/excel-prog...materials.html.

    Ciao,
    Holger

  15. #15
    Registered User
    Join Date
    05-09-2013
    Location
    New York, NY
    MS-Off Ver
    Excel 2003
    Posts
    7

    Re: Delete Specific Row up to a certain word

    Thanks Holger,

    One last one, yeah right. I searched all over the web and played with it but no luck. I have three the following words in a row, I want to delete the word other two rows(Test Sample & Test Second Sample) and keep the word test, how do i do that?

    Test Sample
    Test Second Sample
    Test

    The code as you have provided it:

    Sub EF921892_1a()
    Dim rngFound As Range
    Dim ws As Worksheet
    For Each ws In Worksheets
    With ws
    Set rngFound = .Range("B:B").Find(what:="Test")
    If Not rngFound Is Nothing And rngFound.Row > 5 Then
    .Range(.Range("B5"), rngFound.Offset(-1, 0)).EntireRow.Delete
    End If
    End With
    Next ws
    End Sub

    Thanks, Jesse

  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: Delete Specific Row up to a certain word

    Hi, Jesse,

    I mentioned it before (and no answer to your quesition should be given unless you act according - at least for the last posting):

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code in [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here

    Ciao,
    Holger

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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