leezac
asked on
Delete rows based on values in columns
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!!!
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!!!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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.
Logic is to delete rows with "F" in column B if there is an "A" in column B.
ASKER
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
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
ASKER
I am going to have to repost and ask another way I think.
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.
Flyster