Vba?

cpc

Registered User.
Local time
Today, 09:31
Joined
Oct 26, 2012
Messages
21
Hi,

Looks pretty basic but I seem to be drawing a blank here. I havae a simple spreadsheet:
Ref# Rev
97 b
98 c
99 c
99 e
100 c
100 b
101 a
102 b

I need to create a simple report but remove the duplicates (ex. Ref# 99,100). I need to delete the older Rev's (Ex Ref# 99 Rev C, Ref# 100 Rev B).

Is this done throughRecordsets? will an SQL query do the trick?

THANK YOU.
 
Try this Query..
Code:
DELETE * FROM theTableName 
WHERE [Ref#] In (SELECT [Ref#] FROM theTableName GROUP BY [Ref#] HAVING Count([Ref#]) > 1);
BE CAREFUL of DELETE Queries ! You have been warned !
 
Thanks for the quick turn around! This query deletes all records with duplicate Ref#s. I would like to keep the Ref# that has the most recent revision.
Example: Keep 99e delete 99c
 
Why delete records you may need in the future? why not simply extract only the most recent ones?

Code:
SELECT [Ref#], Max([Ref]) LastRef FROM theTableName GROUP BY [Ref#]

Just FYI, I can advice you to not use something like # in column names, it can cause issues here or there.... Instead use a proper NR or Number
 
Thanks for the reminder on the # in column names. Changed it to Ref. Also great idea not to delete records. Unfortunately I am unfamiliar with the Max([Ref]) Last Ref function. Would you have an example of this?

Again, Thanks.
:cool:
 
Thanks for the reminder on the # in column names. Changed it to Ref. Also great idea not to delete records. Unfortunately I am unfamiliar with the Max([Ref]) Last Ref function. Would you have an example of this?

Again, Thanks.
:cool:

Actually, I believe that he did, but I think he had a Type-o. Below is an updated version of the Query that had your latest mod in it.

I believe that the Ref was intended to be Rev, and that LastRev is an Alias label for the returned value of the Max() Function.

-- Rookie

Code:
SELECT [Ref], Max([B][COLOR=red][Rev][/COLOR][/B]) [B][COLOR=red]AS [/COLOR][COLOR=red]LastRev[/COLOR][/B] FROM theTableName GROUP BY [Ref]
 
Last edited:

holy typo batrookie, well spotted and will fixed :)
 
Actually, I believe that he did, but I think he had a Type-o. Below is an updated version of the Query that had your latest mod in it.

I believe that the Ref was intended to be Rev, and that LastRev is an Alias label for the returned value of the Max() Function.

-- Rookie

Code:
SELECT [Ref], Max([B][COLOR=red][Rev][/COLOR][/B]) [B][COLOR=red]AS [/COLOR][COLOR=red]LastRev[/COLOR][/B] FROM theTableName GROUP BY [Ref]


Brilliant in its simplicity!! Always learn something new with you guys!
THANK YOU!:D
 

Users who are viewing this thread

Back
Top Bottom