MrExcel Message Board

Go Back   MrExcel Message Board > Question Forums > Excel Questions

Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only.

Reply
 
Thread Tools Display Modes
Old Apr 22nd, 2002, 06:19 AM   #1
duckfoot
New Member
 
Join Date: Apr 2002
Posts: 22
Default

I'm not sure if it can be easily done but I have a column 20000 or so rows long and have been asked to tidy it up. I have repeated data throughout the column and so (when i sort it) may have, say: 5 rows of xxxx, 16 rows of yyyy and then 1 row of zzzz, etc... I need to know how to quickly delete the repeated entries leaving just the first cell of a series of identical entries. Maybe a macro, or some lind of function... Please help. I can't go through it manually, it'll take a week!!!
duckfoot is offline   Reply With Quote
Old Apr 22nd, 2002, 06:40 AM   #2
memicol
 
Join Date: Apr 2002
Posts: 16
Default

What about Avanced Filter > Unique Records Only ?
memicol is offline   Reply With Quote
Old Apr 22nd, 2002, 07:52 AM   #3
duckfoot
New Member
 
Join Date: Apr 2002
Posts: 22
Default

thanks for replying but unfortunately it doesn't work... i actually have 4 columns and need to simply remove repetitions in the first leaving a blank cell:
T25400.....buxton ltd
...................buxton ltd
...................buxton ltd
X73900.....AMCT
...................AMCT
T76399.....ATS
I'm not sure if its possible to be honest so never mind...
thanks anyhow

[ This Message was edited by: duckfoot on 2002-04-22 06:53 ]

[ This Message was edited by: duckfoot on 2002-04-22 06:53 ]

[ This Message was edited by: duckfoot on 2002-04-22 06:54 ]

[ This Message was edited by: duckfoot on 2002-04-22 06:54 ]

[ This Message was edited by: duckfoot on 2002-04-22 06:54 ]
duckfoot is offline   Reply With Quote
Old Apr 22nd, 2002, 08:06 AM   #4
memicol
 
Join Date: Apr 2002
Posts: 16
Default

Try this (assumes you data is in columns A:D) :-

Columns(1).Insert
With Range([B2], [B65536].End(xlUp)).Offset(0, -1)
.FormulaR1C1 = "=IF(RC[1]=R[-1]C[1],1,"""")"
.SpecialCells(xlCellTypeFormulas, 1).Offset(0, 1).ClearContents
.EntireColumn.Delete
End With
memicol is offline   Reply With Quote
Old Apr 22nd, 2002, 08:19 AM   #5
Mark W.
MrExcel MVP
 
Join Date: Feb 2002
Location: Austin, Texas USA
Posts: 11,654
Default

Does you boss actually need the duplicates deleted or simply not displayed so the listing is easier to read?

You could apply a conditional format using the formula, =A2=A1, that applies a font color that matches the cell background pattern.

Deleting such duplicate entries makes the list unusable for AutoFilters and PivotTables.

[ This Message was edited by: Mark W. on 2002-04-22 07:21 ]
Mark W. is offline   Reply With Quote
Old Apr 22nd, 2002, 12:36 PM   #6
shades
Board Regular
 
shades's Avatar
 
Join Date: Mar 2002
Location: Near the Land of Oz
Posts: 1,550
Default

Someone posted this on another site. It works well, even though the loop takes a while. Since I am not a programmer, I haven't fine-tuned it. It works.

Note: The item checking for duplicates is in column A.

------

Sub delete_duplicates()
rowx = 1
Do Until Cells(rowx + 1, 1).Value = ""
If UCase(Cells(rowx, 1).Value) = UCase(Cells(rowx + 1, 1).Value) Then
Cells(rowx + 1, 1).EntireRow.Delete
Else
rowx = rowx + 1
End If
Loop
End Sub

__________________
- old, slow, and confused
... but at least I'm inconsistent -

(retired Excel 2003 user, 3.28.2008)
shades is offline   Reply With Quote
Old Apr 22nd, 2002, 06:09 PM   #7
Amds
 
Join Date: Mar 2002
Posts: 22
Default

Quote:
On 2002-04-22 11:36, shades wrote:
Someone posted this on another site. It works well, even though the loop takes a while. Since I am not a programmer, I haven't fine-tuned it. It works.

Note: The item checking for duplicates is in column A.

------

Sub delete_duplicates()
rowx = 1
Do Until Cells(rowx + 1, 1).Value = ""
If UCase(Cells(rowx, 1).Value) = UCase(Cells(rowx + 1, 1).Value) Then
Cells(rowx + 1, 1).EntireRow.Delete
Else
rowx = rowx + 1
End If
Loop
End Sub


But Duckfoot wants to clear the contents of the duplicate cells in column A, not delete the entire row.
In any event, the code posted by "memicol" is more efficient.
Amended to include error handler :-

Application.Screenupdating=false
Columns(1).Insert
With Range([B2], [B65536].End(xlUp)).Offset(0, -1)
.FormulaR1C1 = "=IF(RC[1]=R[-1]C[1],1,"""")"
On Error Resume Next
.SpecialCells(xlCellTypeFormulas, 1).Offset(0, 1).ClearContents
On Error GoTo 0
.EntireColumn.Delete
End With


Note : Code to do the same thing could be created with the macro recorder (no VBA knowledge required).
Also, if it is only a one-off requirement, just do it manually without recording the macro.
Amds is offline   Reply With Quote
Old Apr 30th, 2002, 08:15 AM   #8
duckfoot
New Member
 
Join Date: Apr 2002
Posts: 22
Default

ok ok... thanks everyone for your help, but i can't quite get it working.
Do i simply need to copy the code suggested by Memicol and refined by AMDS as the code of a macro? If so, how come it finishes: "ends with" instead of "end sub"? Sorry if i'm being stupid...
duckfoot is offline   Reply With Quote
Old Apr 30th, 2002, 08:15 AM   #9
duckfoot
New Member
 
Join Date: Apr 2002
Posts: 22
Default

ok ok... thanks everyone for your help, but i can't quite get it working.
Do i simply need to copy the code suggested by Memicol and refined by AMDS as the code of a macro? If so, how come it finishes: "ends with" instead of "end sub"? Sorry if i'm being stupid...
duckfoot is offline   Reply With Quote
Old Apr 30th, 2002, 08:24 AM   #10
Asala42
Board Regular
 
Join Date: Feb 2002
Location: Southfield,MI USA
Posts: 1,027
Default

Hiya,

I see a lot of coding for this question but if you have the data sorted already, why not use a quick formula?

In an inserted blank column (starting with say A2): =if(B2=B1,"",B2)

Then copy/paste it over as values, then delete or hide the original column.

Adam
Asala42 is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT -4. The time now is 09:08 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
All contents Copyright 1998-2012 by MrExcel Consulting.
diabetic desserts recipes recipes Diabetic Soups Holiday Pizza Recipes Popcorn Recipes Recipes For Microwave Pasta Recipes Casserole Recipes Chili Recipes Curry Recipes Crockpot Recipes Apples Recipes Bread Recipes Vegetarian Recipes Vegetable recipes Desserts Recipes Appetizers Ethnic Recipes Meat Dishes Barbecue Recipes Sauces Recipes Marinade Recipes Low Fat Recipes Frugal Gourmet Kitchen Classics Recipes On The Grill Cook Books Seafood Recipes Cajun Recipes Breads Low Fat Low Fat Breads Bread Machine Recipes Yeast Breads Quick Breads Fat Free Vegetarian Salad Recipes Eggplant Recipes Radish Recipes Tomato Recipes Jalapeno Recipes Potato Recipes Lettuce Recipes Cabbage Recipes Beans Ambrosia Recipes Biscotti Recipes Desserts Low Fat Cookie Recipes Cheesecake Recipes Cake Recipes Pie Recipes Muffin Recipes Custard Recipes Best Appetizers Appetizers Low Fat Salsa Recipes Dip Recipes International Recipes Afghan Recipes Alaska Recipes French Recipes German Recipes Greek Recipes Italian Recipes Spanish Recipes Thai Recipes Korean Recipes Chinese Recipes Mexican Recipes Indian Recipes Beef Recipes Pork Pork & Ham Pork Butts Pork Chop Recipes Pork Ribs Rulled Pork Poultry Recipes Stews Recipes Ground Beef Barbecue Grill Barbecue Smoker All Purpose Sauce BBQ Sauce Barbecue Sauce Carolina BBQ Sauce Pickle Recipes Marinades Smoking Low Fat Appetizers & Dips Low Fat Breakfast Low Fat Cakes Low Fat Cheesecakes Low Fat Cookies Low Fat Desserts Low Fat Fish & Seafood Low Fat Meats Low Fat Pasta Low Fat Pies Low Fat Salads Low Fat Sandwiches Low Fat Sauces & Condiments Low Fat Sides Low Fat Soups Low Fat Vegetarian Baker's Dozen Taste of Home Recipe Book Bon Appetit Cookbook Blacktie Cookbook Buster Cook Book Cookbook USA Cook Book Cook Book Sara's Cookbook Sara's Cookbook Appetizers and Dips Poultry recipes Diabetic recipes Holiday recipes Miscellaneous recipes 110 recipes 1986 Usenet cookbook 2900 recipes Cyberrealm recipes Great sysops of world Specialty recipes Ceideburg recipes Cheese recipes Chili recipes Fruits recipes Garlic recipes Great chefs of NY Londontowne recipes Raisins recipes Recipes for kids US Food Vegetarian recipes Bread recipes Drinks Meat Dishes Brisket recipes Caribou recipes Chicken recipes Filet mignons recipes Pork recipes Swordfish recipes Turkey recipes Pasta recipes Uncategorized recipes Ethnic recipes Canada recipes English recipes Ethiopia recipes Germany recipes Greece recipes Mexican recipes Philippines recipes Welsh recipes Microwave recipes Soups recipes Vegetable recipes Asparagus recipes Barley recipes Brown rice recipes Lentil recipes Mushrooms recipes Salads recipes Wild rice Desserts recipes Cakes recipes Chocolate recipes Cookies recipes Ice cream recipes