Sorting

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

Guest

I am trying to sort for some pretty specific stuff and delete everything
else.

Sort Column A for the letters Whse: ## and Column B for the letters Source:
###
the ###'s vary but I want everything with those letters in it selected and
EVERYTHING ELSE deleted. Make Sense?

EX:
If Column A has Whse: ## AND Column B has Source: ### Then Delete
everything else.

I know it's a mess and I'm getting nowhere. Any input would be GREATLY
appreciated. THANKS!!!
 
to not delete both columns A and B on that row must contain the strings

set lastrow = cells(rows.count,1).End(xlup).row
for i = lastrow to 1 step -1
if instr(1,cells(i,1),"Whse: ", vbTextCompare) > 0 and _
instr(1,cells(k,2),"Source: ", vbTextCompare) > 0 then
' do nothing
else
if rng is nothing then
set rng = cells(i,1)
else
set rng = union(rng,cells(i,1))
end if
end if
Next
if not rng is nothing then
rng.Entirerow.Delete
End if

or
If either contains the specific string, then don't delete


set lastrow = cells(rows.count,1).End(xlup).row
for i = lastrow to 1 step -1
if instr(1,cells(i,1),"Whse: ", vbTextCompare) > 0 or _
instr(1,cells(k,2),"Source: ", vbTextCompare) > 0 then
' do nothing
else
if rng is nothing then
set rng = cells(i,1)
else
set rng = union(rng,cells(i,1))
end if
end if
Next
if not rng is nothing then
rng.Entirerow.Delete
End if
 

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