Delete but only if exact

Posted on 2014-08-12
Last Modified: 2014-08-12
I am trying to delete several words from my file but because two words are similar it deletes both. i.e. if I have PEARS, APPLES AND RED APPLES I only want to delete PEARS AND APPLES but keep all rows containing RED APPLES and the header row.

Could an expert help me with VBA code to do this please. .

Thanks in advance
Question by:Jagwarman
    LVL 47

    Accepted Solution


    If your words are on Col A

    pls try

    Sub macro1()
    LastRow = Range("A" & Rows.Count).End(xlUp).Row
    For Idx = LastRow To 2 Step -1
        If Cells(Idx, "A") = "APPLE" Or Cells(Idx, "A") = "PEARS" Then
            Cells(Idx, "A").EntireRow.Delete
        End If
    End Sub

    LVL 47

    Expert Comment

    OR you could use a filter to select the ones with APPLES And the ones with PEARS

    to delete them and the clear the filter

    Author Comment

    Perfect Rgonzo1971 many thanks

    Author Closing Comment

    always delivers thanks

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Threat Intelligence Starter Resources

    Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

    Drop Down List with Unique/Distinct Values (enhancing the Combo-Box with a few steps and a little code) David miller (dlmille) Intro Have you ever created a data validation list from a database field or spreadsheet column (e.g., Zip Codes or Co…
    Approximate matching with VLOOKUP and MATCH seems to me to be a greatly under-used technique, and one which is vital for getting good performance out of large lookups. Until recently I would always have advised using an exact match for simplicity an…
    The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …
    Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now