?
Solved

Delete but only if exact

Posted on 2014-08-12
4
Medium Priority
?
115 Views
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
0
Comment
Question by:Jagwarman
  • 2
  • 2
4 Comments
 
LVL 54

Accepted Solution

by:
Rgonzo1971 earned 2000 total points
ID: 40255321
Hi,

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
Next
End Sub

Regards
0
 
LVL 54

Expert Comment

by:Rgonzo1971
ID: 40255325
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
0
 

Author Comment

by:Jagwarman
ID: 40255363
Perfect Rgonzo1971 many thanks
0
 

Author Closing Comment

by:Jagwarman
ID: 40255365
always delivers thanks
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
This article describes a serious pitfall that can happen when deleting shapes using VBA.
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

862 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