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 Feb 25th, 2002, 01:25 AM   #1
Guest
 
Posts: n/a
Default

hi,

Is it possible to delete identical rows in a sheet. (each row has about 10 cells of information: if all cells are identical I want to delete the row) I want to build a macro which does this everytime a user closes the sheet. (so on workbook_beforeclose)

Hope anyway can help me on the way.

Thnks!

Remi
Holland.
  Reply With Quote
Old Feb 25th, 2002, 02:16 AM   #2
Autolycus
 
Join Date: Feb 2002
Posts: 39
Default

Do you want to delete a row if it is the same as another row?
Or do you want to delete a row if all the data in each cell of that row is the same?
Autolycus is offline   Reply With Quote
Old Feb 25th, 2002, 06:33 AM   #3
Guest
 
Posts: n/a
Default

The second one you suggest.

Would you know a solution?
thnks!
  Reply With Quote
Old Feb 25th, 2002, 07:49 AM   #4
Autolycus
 
Join Date: Feb 2002
Posts: 39
Default

Just to clarify what you want:- If the contents in each of the cells in A3:J3(for example) are the same, row 3 should be deleted.

Try the following. It is assumed that the data in all rows start in column A

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Dim sh As Worksheet
Dim rng1 As Range, rng2 As Range, cell As Range
Dim cCount%, Lc%, x%, toDelete As Range
Set sh = Worksheets("Sheet1") 'Change sheet name as necessary
Application.EnableEvents = False
Application.ScreenUpdating = False
Set rng1 = Intersect(sh.UsedRange, Columns(1))
For Each cell In rng1
Lc = Cells(cell.Row, 256).End(xlToLeft).Column
Set rng2 = Range(Cells(cell.Row, 1), Cells(cell.Row, Lc))
cCount = rng2.Cells.Count
If Application.WorksheetFunction.CountIf(rng2, cell) = cCount Then
If x = 1 Then
Set toDelete = Union(toDelete, cell)
Else
Set toDelete = cell
x = 1
End If
End If
Next
toDelete.EntireRow.Delete
ActiveWorkbook.Save
Application.EnableEvents = True
End Sub
Autolycus is offline   Reply With Quote
Old Feb 27th, 2002, 06:45 AM   #5
Juan Pablo González
MrExcel MVP
 
Join Date: Feb 2002
Location: Bogota, Colombia
Posts: 11,927
Default

There's no need to do a macro here. You can use Excel's built in features that work much better !

Select the data, go to Data, Filter, Advanced Filter. In there, check "Unique Records Only" and you have two choices, you can copy the results to someplace else or you can just click Ok to show the results in the same location.
__________________
Regards,

Juan Pablo González
http://www.juanpg.com
Juan Pablo González is offline   Reply With Quote
Old Feb 27th, 2002, 06:51 AM   #6
Autolycus
 
Join Date: Feb 2002
Posts: 39
Default

Quote:
On 2002-02-27 05:45, Juan Pablo G. wrote:
There's no need to do a macro here. You can use Excel's built in features that work much better !

Select the data, go to Data, Filter, Advanced Filter. In there, check "Unique Records Only" and you have two choices, you can copy the results to someplace else or you can just click Ok to show the results in the same location.
But that's not what the poster wants to do.
Autolycus is offline   Reply With Quote
Old Feb 27th, 2002, 08:07 AM   #7
Juan Pablo González
MrExcel MVP
 
Join Date: Feb 2002
Location: Bogota, Colombia
Posts: 11,927
Default

Then record a macro to do the ADvanced Filter... I bet it's just "a little" faster.
__________________
Regards,

Juan Pablo González
http://www.juanpg.com
Juan Pablo González is offline   Reply With Quote
Old Feb 27th, 2002, 08:07 AM   #8
Guest
 
Posts: n/a
Default

Quote:
On 2002-02-25 01:16, Autolycus wrote:
Do you want to delete a row if it is the same as another row?
Or do you want to delete a row if all the data in each cell of that row is the same?
Can you give me a macro for the first problem?(delete a row if it is the same as another rouw?Many thanks
  Reply With Quote
Old Feb 27th, 2002, 03:38 PM   #9
Autolycus
 
Join Date: Feb 2002
Posts: 39
Default

Quote:
On 2002-02-27 07:07, Juan Pablo G. wrote:
Then record a macro to do the ADvanced Filter... I bet it's just "a little" faster.

A little faster than what? The macro I posted does not do the same thing as retaining only unique records.
I asked the poster(or at least thought I had asked) if he wanted to retain unique records and he replied no.
Obviously my question was not phrased very well because he is now asking for a macro to do that.



[ This Message was edited by: Autolycus on 2002-02-27 14:44 ]
Autolycus is offline   Reply With Quote
Old Feb 27th, 2002, 03:43 PM   #10
Autolycus
 
Join Date: Feb 2002
Posts: 39
Default

Quote:
On 2002-02-27 07:07, Anonymous wrote:
Quote:
On 2002-02-25 01:16, Autolycus wrote:
Do you want to delete a row if it is the same as another row?
Or do you want to delete a row if all the data in each cell of that row is the same?
Can you give me a macro for the first problem?(delete a row if it is the same as another rouw?Many thanks
Record a macro as suggested by Juan Pablo G :-
"Select the data, go to Data, Filter, Advanced Filter. In there, check "Unique Records Only" and you have two choices, you can copy the results to someplace else or you can just click Ok to show the results in the same location."

Autolycus 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 11:46 PM.


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