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 May 22nd, 2002, 01:37 PM   #1
Man of Action
New Member
 
Join Date: Apr 2002
Posts: 15
Default

Hi all,

Here is my problem:

I have two spreadsheets. Both pretty darn big. They both contain simialr data but not all is the same. What I want to do is search both spreadsheets and pick out the data that is the same on both sheets. Can anyone please offer some advice?

Thanks,
MOA


_________________
The internet! Is that thing still around?

[ This Message was edited by: Man of Action on 2002-05-22 12:39 ]

[ This Message was edited by: Man of Action on 2002-05-22 12:40 ]
Man of Action is offline   Reply With Quote
Old May 22nd, 2002, 02:07 PM   #2
Man of Action
New Member
 
Join Date: Apr 2002
Posts: 15
Default

Please someone help me!?!?!
Man of Action is offline   Reply With Quote
Old May 22nd, 2002, 02:07 PM   #3
Al Chara
MrExcel MVP
 
Join Date: Feb 2002
Location: Monterrey, Mexico
Posts: 1,433
Default

Can you clarify for me...when you say data that is the same...do you mean that, for example, if sheet 1 A1 contains the same value as sheet 2 A1? Also, is your data all formulas, all values, or a mixture?
__________________
Kind regards,

Al Chara
Al Chara is offline   Reply With Quote
Old May 22nd, 2002, 02:12 PM   #4
Man of Action
New Member
 
Join Date: Apr 2002
Posts: 15
Default

I am sorry for the confusion. The data is numbers. Some numbers are the same in both spreadsheets but not in the same orders. For example A1 on sheet 1 might be 2000 and A1 on sheet 2 might be 12843. But 2000 might not necessarily be on sheet 2. So I need a list of all the duplicates from both sheets.

Does this clarify?
MOA

Man of Action is offline   Reply With Quote
Old May 22nd, 2002, 02:25 PM   #5
Damon Ostrander
MrExcel MVP
 
Damon Ostrander's Avatar
 
Join Date: Feb 2002
Location: Denver, Colorado USA
Posts: 4,014
Default

Hi MOA,

You didn't define what you mean by "pick out". If you just mean to highlight the cells that are the same, the following macro will do it. With minor modifications this macro could copy the common data to another sheet, or delete the non-common data from one of the sheets being tested.

Sub HighlightCommonData()
If ActiveWindow.SelectedSheets.Count <> 2 Then
MsgBox "Two sheets must be selected", vbExclamation, "Highlight Common Data"
Exit Sub
End If
Dim iRow As Long
Dim iCol As Integer
With ActiveWindow.SelectedSheets(1)
For iRow = .UsedRange.Row To .UsedRange.Row + .UsedRange.Rows.Count
For iCol = .UsedRange.Column To .UsedRange.Columns.Count
If Not IsEmpty(.Cells(iRow, iCol)) Then
If .Cells(iRow, iCol) = ActiveWindow.SelectedSheets(2).Cells(iRow, iCol) Then
.Cells(iRow, iCol).Interior.ColorIndex = 6
End If
End If
Next iCol
Next iRow
End With
End Sub

To use this macro, select the two sheets that you want to compare, then run the macro. The similarities will be highlighted on the active worksheet.
__________________
Keep Excelling.

Damon

VBAexpert Excel Consulting
(My other life: http://damonostrander.com )
Damon Ostrander is offline   Reply With Quote
Old May 22nd, 2002, 02:25 PM   #6
Al Chara
MrExcel MVP
 
Join Date: Feb 2002
Location: Monterrey, Mexico
Posts: 1,433
Default

Are the ranges the same on both sheets? What are the ranges? Can there be duplicates?

[ This Message was edited by: Al Chara on 2002-05-22 13:29 ]
Al Chara is offline   Reply With Quote
Old May 22nd, 2002, 02:39 PM   #7
Man of Action
New Member
 
Join Date: Apr 2002
Posts: 15
Default

No the ranges are not the same. One is bigger that the other.

How do I modify the above code to copy the duplicates to a seperate spreadsheet?
Man of Action is offline   Reply With Quote
Old May 22nd, 2002, 02:47 PM   #8
Asala42
Board Regular
 
Join Date: Feb 2002
Location: Southfield,MI USA
Posts: 1,030
Default

Hey,

If you can live with a formula approach (a bit more manual than VBA), you can probably go with a vlookup or countif. Copy this formula down a column adjacent to one of your lists:

=IF(COUNTIF(Sheet2!$A$2:$A$100,A2)>0,"present","not present")

You can then apply a quick autofilter (for "present") and then copy/paste the visible cells to your other sheet.

Hope that helps,
Adam
Asala42 is offline   Reply With Quote
Old May 22nd, 2002, 03:32 PM   #9
Al Chara
MrExcel MVP
 
Join Date: Feb 2002
Location: Monterrey, Mexico
Posts: 1,433
Default

MOA,

I had the same idea as Adam. If you want to do it in VBA then try the following code. Make sure you have a blank sheet 3. This is where the data will be copied.

I assumed that your list could expand past column A. If this is not true and your data only exists in Column A then I can simply the code for you. Repost if necessary.

Sub CheckWS()
Dim LargeRng As Range, SmallRng As Range
Set rng1 = Sheet1.UsedRange
Set rng2 = Sheet2.UsedRange
If rng1.Cells.Count > rng2.Cells.Count Then
Set LargeRng = rng1
Set SmallRng = rng2
Else:
Set LargeRng = rng2
Set SmallRng = rng1
End If

Sheet3.[a1].Formula = "=IF(COUNTIF(" & LargeRng.Worksheet.Name & _
"!" & LargeRng.Address & "," & SmallRng.Worksheet.Name & "!A1)>0," _
& SmallRng.Worksheet.Name & "!A1,"""")"

Sheet3.[a1].AutoFill Destination:=Sheet3.Range("a1:a" & LargeRng.Rows.Count), _
Type:=xlFillDefault

Sheet3.Range("a1:a" & LargeRng.Rows.Count).AutoFill Destination:=Sheet3.Range("a1:" & Cells(LargeRng.Rows.Count, LargeRng.Columns.Count).Address), _
Type:=xlFillDefault
End Sub
__________________
Kind regards,

Al Chara
Al Chara 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 05:09 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