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 11th, 2002, 06:42 AM   #1
Noir
Board Regular
 
Join Date: Mar 2002
Posts: 364
Default

I have 2 spreadsheets. Each spreadsheet has a series of serial numbers (or other kind of data) listed from A2:A900. I am trying to use the following code to tell me when there is similar data contained in A2:A900 of "both" spreadsheets. The problem is, this code misses a lot of data. Please tell me how i can correct it;

Sub DuplicatesCheck()
Application.ScreenUpdating = False
Sheets("Sheet1").Select
Range([A2], [A65536].End(xlUp)).Offset(0, 1).Formula = "=IF(COUNTIF(Sheet2!RC[-1]:Sheet2!R[598]C[-1],RC[-1])<>0,""Yes"",""No"")"
Dim theCol As Range, cell As Range, RtoSel As Range
Dim LtoSel As String
Set theCol = Range(Range("B2"), Range("B65536").End(xlUp))
LtoSel = "Yes"
For Each cell In theCol
If Right(cell, 3) = LtoSel Then
If RtoSel Is Nothing Then
Set RtoSel = cell
Else
Set RtoSel = Application.Union(RtoSel, cell)
End If
End If
Next
On Error GoTo e
RtoSel.Offset(0, -1).Select
With Selection
.Font.FontStyle = "Bold"
.Interior.ColorIndex = 3
End With
Range([B2], [B65536].End(xlUp)).Clear
[A1].Select
Application.ScreenUpdating = True
Exit Sub
e:
MsgBox "There are no duplicates.", 64, "Time for a beer !"
[A1].Select
End Sub

Thanks,
Noir
Noir is offline   Reply With Quote
Old Apr 11th, 2002, 07:26 AM   #2
Tom Urtis
MrExcel MVP
 
Tom Urtis's Avatar
 
Join Date: Feb 2002
Location: San Francisco, California USA
Posts: 10,387
Default

Noir,

I recognize your macro as 2 separate pieces of code I have posted on this board recently, each for two different questions that were asked. Each portion of code works based on the question that was asked for which that code was intended. It is hard (at least for me) to say why you are experiencing a problem with the two combined, so please email me your spreadsheet and I'll be happy to look at it and see exactly what you are trying to do.

My email is TomUrtis@attbi.com.


__________________
Tom Urtis
Microsoft MVP - Excel
Tom Urtis is offline   Reply With Quote
Old Apr 11th, 2002, 09:10 AM   #3
Noir
Board Regular
 
Join Date: Mar 2002
Posts: 364
Default

Thanks Tom, I will e-mail my spreadsheets to you.

Noir
Noir is offline   Reply With Quote
Old Apr 11th, 2002, 10:01 AM   #4
Noir
Board Regular
 
Join Date: Mar 2002
Posts: 364
Default

Tom,
I received a Delivery Failure message when i tried to send you an e-mail.

The problem is pretty simple though. The code will not recognize all of the serial numbers within both sheets. It only recognizes a few. Maybe i did not copy your code to the right place. Does it go in "This Workbook" or in a Module?

Noir
Noir is offline   Reply With Quote
Old Apr 12th, 2002, 06:33 AM   #5
Tom Urtis
MrExcel MVP
 
Tom Urtis's Avatar
 
Join Date: Feb 2002
Location: San Francisco, California USA
Posts: 10,387
Default

Noir,

I received your email; what you call a "spreadsheet" is commonly called a "workbook". You sent me two workbooks, and now I see that you were trying to compare two lists of serial numbers, each located in separate workbooks. The macro code assumed the two different lists were on separate spreadsheets in the same workbook.

For this sort of comparison work you'd be better off housing (at least temporarily) all information in the same workbook, and then the macro will work.

To do that, try prefacing the code you now have with a few lines to import the serial numbers from one file to another. Importing is better than paste links in my opinion; all those formulas slow down the destination file, and annoy other users with that "Update links?" prompt (which can be bypassed but that's another story).

Anyway, insert this code at the beginning of your macro, assuming the destination file is the one named “3rd_Floor.xls”, where the macro is located:

Application.ScreenUpdating = False
Application.DisplayAlerts = False
Application.EnableEvents = False
Workbooks.Open Filename:="C:YourFilePath5th_Floor.xls"
ThisWorkbook.Worksheets("Sheet2").Range("A1:A1000").Value = _
Workbooks("5th_Floor.xls").Worksheets("Sheet1").Range("A1:A1000").Value
Workbooks("5th_Floor.xls").Close


‘Sidebar, your existing macro code goes here


‘Place this at the end of the macro:

‘Optional, just to clear A1:A1000 of text data in Sheet2, although it’s too small to slow down your file:
Worksheets("Sheet2").Range("A1:A1000").Clear

‘Not optional; insert this at the very end:
ThisWorkbook.Save
Application.EnableEvents = True
Application.DisplayAlerts = True
Application.ScreenUpdating = True


Modify “YourFilePath” with the file path where 5th_Floor.xls is located.

Finally, be sure to not change the file path, workbook name, or “Sheet1” sheet name of the 5th_Floor.xls file. There is alternate code to not worry about the sheet name tab changing but this code here will be easier for you and other users to track. If the aforementioned does get changed, you will receive an out of range run time error, reminding you that you must have the aforementioned reflect what the macro code is instructed to look for. Down the road we can put in an error trap to make the run time error less ugly, but that’s probably superfluous for now.

Hope this helps; let us know how it turns out.
__________________
Tom Urtis
Microsoft MVP - Excel
Tom Urtis 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 10:27 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