Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Delete rows based on values in columns

Posted on 2013-11-12
6
Medium Priority
?
356 Views
Last Modified: 2013-11-13
Can someone please help with this - I can't figure how the logic will work.

I have on sheet1 where I need to delete rows for A1 to end of last used row where

if column B has "A" or "F" to delete the rows where B = "F" else
if column B has "F" but not "A" do not delete rows.....


Thanks in advance!!!
0
Comment
Question by:leezac
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 22

Expert Comment

by:Flyster
ID: 39643381
Exactly how does your data appear in column B? In your logic, should it be column B has "A" AND "F"?

Flyster
0
 
LVL 14

Accepted Solution

by:
Faustulus earned 2000 total points
ID: 39643721
This code will delete all rows where column B contains both, "F" and "A".
Option Explicit

Sub DeleteFA()

    Const FirstDataRow As Long = 1
    Dim R As Long
    Dim CellVal As String
    
    Application.ScreenUpdating = False
    With ActiveSheet.Columns(2)         ' 2 = column B
        For R = .Cells(.Rows.Count).End(xlUp).Row To FirstDataRow Step -1
            CellVal = .Cells(R).Value
            If InStr(1, CellVal, "F", vbTextCompare) And _
               InStr(1, CellVal, "A", vbTextCompare) > 0 Then
               .Cells(R).EntireRow.Delete
            End If
        Next R
    End With
    Application.ScreenUpdating = True
End Sub

Open in new window

It will not delete rows where only "F" is found. The code will find "F" as well as "f", "A" as well as "a", and the two characters can be in any sequence, interspersed with other characters or numbers.
0
 

Author Comment

by:leezac
ID: 39644794
Thanks so much but I need to keep rows that do NOT contain F or A which will be blank.

Logic is to delete rows with "F" in column B if there is an "A" in column B.
0
Industry Leaders: 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!

 

Author Comment

by:leezac
ID: 39644860
I think I have part of the solution.  
If there is an "A" and "F" in column "B" delete the F rows

else if there is an "F" only and NOT "A" - do not delete the "F" rows

May need to add another column with true and false logic.  Not sure what to do....

Sub Delete_Rows()
Dim r As Long
 Sheets("Sheet3").Select

For r = Range("B" & Rows.Count).End(xlUp).Row To 1 Step -1
If UCase(Left(Cells(r, "B").Text, 8)) = "F" Then Rows(r).Delete
Next r
End Sub
0
 

Author Closing Comment

by:leezac
ID: 39646308
I am going to have to repost and ask another way I think.
0
 
LVL 14

Expert Comment

by:Faustulus
ID: 39646700
Perhaps the best way is to test my code and tell me what it does wrong. The test is all set up, and you might simply say which rows (by number) were deleted and should not have been and which rows should have been deleted but were not.
0

Featured Post

Industry Leaders: 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

This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
Excel can be a tricky bit of software to get your head around. Whilst you’ll be able to eventually get to grips with the basic understanding of how to get by, there are a few Excel tips that not everybody will even know about let alone know how to d…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

636 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