VBA to remove records

S

Shon

I am just starting to learn VBA and really struggling with the following
problem. Any help would be appreciated!.

I have a list of Excel records which this time round is 4 columns and 45000
records. the columns will always be the same with the same headers but the
number of records will change each time. My data looks like the following;

Item No Trans Qty Doc Number Location
4001 100 50001 EL4
4001 100 50001 EL7
4001 100 50001 EL9
4001 100 50001 EL4
4002 50 30001 3BJ
4002 50 30001 2DC
4002 50 30001 3BJ
4003 40 20001 EL4
4003 40 20001 EL7

I want to use a macro to look down the data and where the Item No, Trans Qty
and Doc Number are the same then keep the 1st record for the 1st location and
remove the other records. There may however be some instances where the Item
No, Trans Qty, Doc Number AND Location are the same e.g. Item No 4001,
Location EL4, and in these cases the records would need to be kept. I would
therefore expect to see the following result;

Item No Trans Qty Doc Number Location
4001 100 50001 EL4
4001 100 50001 EL4
4002 50 30001 3BJ
4002 50 30001 3BJ
4003 40 20001 EL4
4003 40 20001 EL7

Any ideas? Many thanks!
 
B

Barb Reinhardt

WIthout providing the code, this is how I'd approach it.

1) Add a helper column with the following concatenated

Item #, TransQty, Doc Number.

You can do this like this

=A2&B2&C2

2) Add another helper column to count the values. Let's say your first
helper is column #, In that column put something like this

=COUNTIF (E:E,E2) Where the concatenated data is in column E and the
current row is 2.

HTH,

Barb Reinhardt
 
K

keiji kounoike

I think you didn't tell us the clear criteria that keep the records even
if Item No, Trans Qty, Doc Number AND Location are the same. I think it
is hard to answer your question without that criteria.

Keiji
 

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

Top