+ Reply to Thread
Results 1 to 6 of 6

Delete entire row if specific text found within cell from range in another tab

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    11-01-2012
    Location
    NJ
    MS-Off Ver
    Excel 365
    Posts
    120

    Delete entire row if specific text found within cell from range in another tab

    Hi,

    I have two tabs - a tab called "Pricing" and a tab called "Funds to be removed"

    I am trying to find all instances that occur within a cells in column H on the Pricing tab and delete that row if part of the cell is in column A on the "Funds to be removed tab.

    For example: Funds to be Removed tab in column a would show "Jon" - in column H on Pricing there will be multiple instances of with the word "Jon" in column H like "12368_Jon", "6548244_Jon", etc

    The code below is what I have written and seems to work but for some reason it does not delete all instances from the pricing tab. I wonder if there is something wrong with either the code or perhaps merged cells or blank rows are screwing up the code.

    Any assistance would be greatly appreciate!

    
    Dim WS1 as Worksheet
    Dim WS2 as Worksheet
    
    Set WS1 = Sheets("Pricing")
    Set WS2 = Sheets("FUNDS TO BE REMOVED")
    
    Sheets("FUNDS TO BE REMOVED").Select
    Cells(2, 1).Select
    TopRowRemove = ActiveCell.row
    Columns("A").Find("", Cells(Rows.Count, "A")).Select
    ActiveCell.Offset(-1, 0).Select
    BottomRowRemove = ActiveCell.row
    
    Sheets(("Pricing")).Select
    Cells(11, 1).Select
    TopRow = ActiveCell.row
    LastRow = ActiveSheet.Range("B1").CurrentRegion.Rows.Count + 2
    
    Application.Calculation = xlManual
     
    For Each rcell In WS2.Range("A" & TopRowRemove & ":A" & BottomRowRemove)
        For Each cell In Sheets("Pricing").Range("H" & TopRow & ":H" & LastRow)
            If cell Like rcell Then cell.EntireRow.Delete
        Next cell
    Next rcell
    
    Application.Calculation = xlAutomatic

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,047

    Re: Delete entire row if specific text found within cell from range in another tab

    Attach a sample workbook (not a picture or pasted copy). Make sure there is just enough data to demonstrate your need. Include a BEFORE sheet and an AFTER sheet in the workbook if needed to show the process you're trying to complete or automate. Make sure your desired results are shown, mock them up manually if necessary.

    Remember to desensitize the data.

    Click on GO ADVANCED and then scroll down to Manage Attachments to open the upload window.
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Forum Contributor
    Join Date
    11-01-2012
    Location
    NJ
    MS-Off Ver
    Excel 365
    Posts
    120

    Re: Delete entire row if specific text found within cell from range in another tab

    Thank you!

    See attached file with a before pricing tab and after pricing tab when macro should run

    Thanks!
    Attached Files Attached Files

  4. #4
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 insider Version 2504 Win 11
    Posts
    24,688

    Re: Delete entire row if specific text found within cell from range in another tab

    Option Explicit
    
    Sub Mikey()
        Dim s1 As Worksheet, s2 As Worksheet
        Set s1 = Sheets("Before Pricing")
        Set s2 = Sheets("FUNDS TO BE REMOVED")
        Dim i As Long, j As Long
        Dim lr As Long, lr2 As Long
        Application.ScreenUpdating = False
        lr = s1.Range("A" & Rows.Count).End(xlUp).Row
        lr2 = s2.Range("A" & Rows.Count).End(xlUp).Row
        For i = lr To 1 Step -1
            For j = 1 To lr2
                If InStr(s1.Range("H" & i), s2.Range("A" & j)) > 0 Then
                    s1.Range("H" & i).EntireRow.Delete
                End If
            Next j
        Next i
        Application.ScreenUpdating = True
        MsgBox "Complete"
    
    End Sub
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  5. #5
    Forum Contributor
    Join Date
    11-01-2012
    Location
    NJ
    MS-Off Ver
    Excel 365
    Posts
    120

    Re: Delete entire row if specific text found within cell from range in another tab

    Works great! Thank you!

  6. #6
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,047

    Re: Delete entire row if specific text found within cell from range in another tab

    You're welcome. Thanks for the rep.

    Looks like the other guys did the work but thanks anyway.


    If you are satisfied with the solution(s) provided, please mark your thread as Solved.


    New quick method:
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

    Or you can use this way:

    How to mark a thread Solved
    Go to the first post
    Click edit
    Click Go Advanced
    Just below the word Title you will see a dropdown with the word No prefix.
    Change to Solved
    Click Save


    You may also want to consider thanking those people who helped you by clicking on the little star at the bottom left of their reply to your question.

+ 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. Found?, then delete entire rows. Not found end sub
    By Andrewstupendo in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-21-2018, 01:56 PM
  2. [SOLVED] Locate Specific Text and Delete the Entire Row
    By leebird in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 12-02-2015, 01:40 AM
  3. VBA code to delete the FILTERED range and moving the cell up (dont Delete entire row)
    By mchilapur in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-14-2015, 07:48 AM
  4. How to delete entire row if first cell of it is empty for specific range and worksheets
    By roshanvmech in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-01-2014, 12:36 PM
  5. [SOLVED] If Or statement to check cell text and delete entire row if text is found
    By VBA FTW in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-08-2013, 11:46 AM
  6. [SOLVED] Locate column with specific title and delete rows if predefined set of text is found
    By johnny_tc in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 10-25-2012, 01:57 PM
  7. [SOLVED] Macro Help: IF specific wording is found in a cell, THEN copy entire row to new sheet
    By csch123 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 06-13-2012, 03:16 PM

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