Delete all row data EXCEPT

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have imported data from an Outlook file that leaves me with an excel
spreadsheet with 2 columns. Data in the columns include groups that I must
keep in the following format:

In column A: I have 8 fields named
txtBusiness,txtName,txtAddress,txtCity,selState,txtZip,txtEmail,and txtPhone

In column B, I have the actual data. However, I also have a lot of other
garbage in column A and B that I do not need and would like to delete with a
macro. I have searched the knowledge base high and low and have found
nothing that seem to fit this application. I simply need to save any row
that has the txtBusiness through txtPhone in column A and the corresponding
data in column B, and delete everything else. Thanks in advance
 
Dim r as Range
Dim i as Long
for i = cells(rows.count,1).End(xlup).Row to 1 step - 1
set r = Cells(i,1)
if instr(r,"txtName") + instr(r,"txtAddress") + instr(r,"txtBusiness") _
+ instr(r,"txtCity") + instr(r,"selState") + instr(r,"txtZip") + _
instr(r,"txtPhone") = 0 then
r.EntireRow.Delete
end if
Next
 
I would bet you could just use autofilter for values in column A which "does
not begin with" txt, and delete the rows?
 
I missed selState, so since custom autofilter gives you up to two criteria,
they should be

"does not begin with " txt

AND

"does not equal" selState
 

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