+ Reply to Thread
Results 1 to 6 of 6

delete rows that do not contain the text from a specific cell

  1. #1
    Registered User
    Join Date
    07-01-2012
    Location
    Tilburg, the Netherlands
    MS-Off Ver
    Excel 2010
    Posts
    96

    delete rows that do not contain the text from a specific cell

    Hi all,

    Just like I mentioned in the topic: I need a macro that will delete rows that do not contain the text from a specific cell. It should delete rows from range A4:A22, and the text is in a cell A27.
    So lets say that there is a text "Venray" in cell A27, this text is also in cells A12 and A20; I want to leave them as they are, but want to delete all other ones from the range of A4:A22.

    I found a code that almost solves my problem, but I still need to change it a little bit:

    Sub delete_It()

    Sheets("Sheet1").Select
    Application.ScreenUpdating = False
    Application.Calculation = xlCalculationManual
    Dim lastrow As Long, r As Long
    lastrow = ActiveSheet.UsedRange.Rows.Count
    For r = lastrow To 1 Step -1
    If Cells(r, 1).Value <> "Sarasin" Then Rows(r).Delete
    Next r
    Application.Calculation = xlCalculationAutomatic
    Application.ScreenUpdating = True
    End Sub


    could you help me with that? Thanks in advance!

  2. #2
    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 rows that do not contain the text from a specific cell

    Hi, Vogelmann,

    IŽd use a cell above the range to be shifted up as criteria range...

    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

  3. #3
    Registered User
    Join Date
    07-01-2012
    Location
    Tilburg, the Netherlands
    MS-Off Ver
    Excel 2010
    Posts
    96

    Re: delete rows that do not contain the text from a specific cell

    perfect!
    thank you Holger
    Last edited by Vogelmann; 10-10-2012 at 05:12 AM.

  4. #4
    Registered User
    Join Date
    07-01-2012
    Location
    Tilburg, the Netherlands
    MS-Off Ver
    Excel 2010
    Posts
    96

    Re: delete rows that do not contain the text from a specific cell

    there is one more thing to do here: how to apply this code to other sheets?
    I mean: delete also rows from in sheet2, column B, that does not contain a value indicated in a cell A27 in sheet1.
    The range is changed in sheet2: B3:B40
    I have 6 sheets in total to deal with.

    Thanks in advance!

  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: delete rows that do not contain the text from a specific cell

    Hi, Vogelamnn,

    does the changed range apply to all worksheets or are the areas different on each sheet? Are there other sheets than those on whioch the rows are to be deleted?

    Basically you could try an approach like this:

    Please Login or Register  to view this content.
    You need to specify the sheet on which the criteria is to be found and the names and ranges if the sheets.

    Ciao,
    Holger

  6. #6
    Registered User
    Join Date
    07-01-2012
    Location
    Tilburg, the Netherlands
    MS-Off Ver
    Excel 2010
    Posts
    96

    Re: delete rows that do not contain the text from a specific cell

    thanks HaHoBe, now I understood how it should be done. Other users helped me with that in another topic, but your solution also works.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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