If "text" exists in COL A, keep (quick one)

  • Thread starter Thread starter Rubix³
  • Start date Start date
R

Rubix³

Hello all

Here's the deal. If "Customer Name:" exists in COL A, keep the row.
if "Customer Totals" exists in B, keep those rows too.

Delete ALL the rest. "Customer Name:" and "Customer Totals" NEVE
appear together on the same row.

Here's what I've started with:

Dim x As Long
For x = 1 To Range("A65536").End(xlUp).Row
If Range("A" & x) <> "Customer Name:" Then
Range("A" & x).EntireRow.Delete
Else
Range("A" & x).EntireRow.Delete
End If
Next

Of course, this will delete the "Customer Totals" rows before th
macro has time to KEEP those rows. Can someone help me merge this wit
"keep COL B If Customer Totals exists?"

Thanks for reading
 
Dim x As Long
For x = Range("A65536").End(xlUp).Row to 1 step -1
If Range("A" & x) <> "Customer Name:" and Range("B" & x) <> _
"Customer Totals" Then
Range("A" & x).EntireRow.Delete
End If
Next

When deleting rows you should work from the bottom rows back to the top
rows.

This requires an exact match for the text you are testing for. If it seems
to fail, the first place to look is thanks that would make the match fail
(trailing spaces, capitalization and so forth).

Test on a copy of your workbook/data.
 
Hello Tom - thanks for the reply.

I ran that macro, left my desk, and when I came back the entire shee
was blank minus 40 misc. rows at the end. Both of the values I'
searching for are text formatted, without spaces or anything else tha
would impair the logic. Any ideas
 
I apologize! It worked like a charm. I had it searching for
*instances* - not exactness.

Thank you Tom.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top