+ Reply to Thread
Results 1 to 7 of 7

VBA to search for specific string and delete range

  1. #1
    Registered User
    Join Date
    08-15-2014
    Location
    Denmark
    MS-Off Ver
    365 Pro
    Posts
    94

    VBA to search for specific string and delete range

    Hi all

    For the attached example sheet, I need some simple VBA to search for every time "Title 1" appears (EXCLUDING the first time), and delete the row + 5 rows down.

    Meaning that in the attached sheet, EntireRow.Delete applies to A29:A34, A71:A76, and so on. The placement of "Title 1" are variable from project to project, but they ALWAYS come in the same pattern of 6 rows :-)

    Things that should remain in the attached sheet should only be Range("1:6") and all the data numbers.

    I hope you guys are able to help :-) Thank you very much!
    Attached Files Attached Files

  2. #2
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,741

    Re: VBA to search for specific string and delete range

    How about
    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    08-15-2014
    Location
    Denmark
    MS-Off Ver
    365 Pro
    Posts
    94

    Re: VBA to search for specific string and delete range

    Quote Originally Posted by Fluff13 View Post
    How about
    Please Login or Register  to view this content.
    Works like a charm - thank you so much!!! :-)

    I know this wasn't a part of the original question - but are there any way to include a string of code to apply "BorderAround" to all the data values (excluding Range("1:6")?

  4. #4
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,741

    Re: VBA to search for specific string and delete range

    How about
    Please Login or Register  to view this content.

  5. #5
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Cool Hi ! Try this …


    According to the attachment as a VBA beginner starter :

    PHP Code: 
    Sub Demo1()
            
    Dim Rg As Range
            Set Rg 
    = [A6].End(xlDown)(0)
        While 
    Not IsEmpty(Rg(2))
            
    Rows(Rg(2).Row).Resize(6).Delete
            Set Rg 
    Rg.End(xlDown)(0)
        
    Wend
        With 
    [A5].CurrentRegion
            
    .Range("B3").Resize(.Rows.Count 2, .Columns.Count 1).BorderAround xlThin
        End With
    End Sub 
    ► Do you like it ? ► ► So thanks to click on bottom left star icon « Add Reputation » ! ◄ ◄

  6. #6
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,957

    Re: VBA to search for specific string and delete range

    With a Helper Column...
    Please Login or Register  to view this content.
    Last edited by Sintek; 06-03-2020 at 01:54 PM.
    Good Luck...
    I don't presume to know what I am doing, however, just like you, I too started somewhere...
    One-day, One-problem at a time!!!
    If you feel I have helped, please click on the [★ Add Reputation] to left of post window...
    Also....Add a comment if you like!!!!
    And remember...Mark Thread as Solved...
    Excel Forum Rocks!!!

  7. #7
    Forum Guru
    Join Date
    04-23-2012
    Location
    New Jersey, USA
    MS-Off Ver
    Excel 365
    Posts
    2,463

    Re: VBA to search for specific string and delete range

    Given how your data is laid out, here is another macro that will do what your original question asked for...
    Please Login or Register  to view this content.
    Last edited by Rick Rothstein; 06-03-2020 at 02:45 PM.

+ 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. [SOLVED] Search string for specific characters, then output characters that reflect range
    By jackmaca in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 02-19-2020, 09:13 AM
  2. [SOLVED] Script to Search for a specific String then return cell values above that String-3
    By owensjb2 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-01-2015, 01:50 PM
  3. [SOLVED] Script to Search for a specific String then return cell values above that String-2
    By owensjb2 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 04-01-2015, 01:00 PM
  4. [SOLVED] Script to Search for a specific String then return cell values above that String
    By owensjb2 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 04-01-2015, 11:28 AM
  5. Search A Range For Specific Text String
    By xybadog in forum Excel Formulas & Functions
    Replies: 29
    Last Post: 01-14-2015, 07:15 AM
  6. [SOLVED] Need to search for a specific string in Column A and delete values within the same row
    By hgeo24 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 02-27-2014, 04:56 PM
  7. Search for any Text String in specific range and copy + offset + move
    By FN2010 in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 05-05-2010, 07:04 PM

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