matching items on 2 sheets

  • Thread starter Thread starter JT
  • Start date Start date
J

JT

My macro pulls data into Sheet (B). Sheet (A) contains up-
to-date balances for some of the items on Sheet (B).
Column A on each sheet contains a reference number.

I want to look at each item on Sheet (A) and see if there
is a match on Sheet (B). If there isn't a match, I want
to delete the item on Sheet (A).

I could start at the top of Sheet (A) and look through all
of the reference numbers on Sheet (B) until I either get a
match or get to the bottom of the list. If I get to the
bottom of Sheet (B), I would delete the item on Sheet (A).

There must be a better way than to cycle though Sheet (B)
for each item on Sheet (A).

Any suggestions or ideas would be greatly appreciated. As
always, thanks for the help.
 
I dont personally agree with deleting data but if that is what you want here
goes...

sub RemoveRows
dim rngToSearch
dim rngToFind as range
dim rngFound as range

set rngToSearch = sheets("SheetB").range("A1:A30") 'no idea how you know
what to search
for each rngTofind in rngToSearch
set rngFound = sheets("SheetA").cells.find(rngTofind.value)
do while not rngFound is nothing
rngfound.entirerow.delete
set rngFound = sheets("SheetA").cells.find(rngTofind.value)
loop
next rngToFind

end sub

or something like that...
 

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