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, 12:08 PM   #1
Noir
 
Join Date: Mar 2002
Posts: 364
Default

The purpose of the code below is to look at a series of serial numbers within my workbook, column A, sheet1 and match them to a series of serial numbers listed in column A, sheet2 of the same workbook. If the code finds a serial number that is located on both sheets, it is supposed to highlight the serial number cell in Column A, sheet1. The problem is, the code will only highlight down column A until if finds a serial number not located on sheet2. At that point the code stops highlighting cells.

How can i make it so the code will highlight the found serial numbers while skipping over the serial numbers it didn't find?

Thx,
Noir



Sub FindDuplicates()
Application.ScreenUpdating = False
Sheets("Sheet1").Select
Range([A2], [A65536].End(xlUp)).Offset(0, 2).Formula = "=IF(COUNTIF(Sheet2!RC[-2]:Sheet2!R[2998]C[-2],RC[-2])<>0,""Yes"",""No"")"
Dim theCol As Range, cell As Range, RtoSel As Range
Dim LtoSel As String
Set theCol = Range(Range("C2"), Range("C65536").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, -2).Select
With Selection
.Font.FontStyle = "Bold"
.Interior.ColorIndex = 18
End With
Range([C2], [C65536].End(xlUp)).clear
[A1].Select
Application.ScreenUpdating = True
Exit Sub
e:
MsgBox "There are no duplicates.", 64, "CONGRATULATIONS !"
[A1].Select
End Sub
Noir is offline   Reply With Quote
Old May 22nd, 2002, 12:54 PM   #2
dimrod
 
Join Date: May 2002
Posts: 73
Default

Your code to enter the formula should be :-

Range([A2], [A65536].End(xlUp)).Offset(0, 2).Formula = "=IF(COUNTIF(Sheet2!R2C1:Sheet2!R3000C1,RC[-2])<>0,""Yes"",1)"


Also, the code could be simplified a bit :-

Sub FindDuplicates()
Application.ScreenUpdating = False
Sheets("Sheet1").Select
Range([A2], [A65536].End(xlUp)).Offset(0, 2).Formula = "=IF(COUNTIF(Sheet2!R2C1:Sheet2!R3000C1,RC[-2])<>0,""Yes"",1)"
On Error GoTo e
With Columns(3).SpecialCells(xlCellTypeFormulas, 2).Offset(0, -2)
.Font.FontStyle = "Bold"
.Interior.ColorIndex = 18
End With
Columns(3).Clear
[A1].Select
Exit Sub
e:
MsgBox "There are no duplicates.", 64, "CONGRATULATIONS !"
On Error GoTo 0
Columns(3).Clear
[A1].Select
End Sub

dimrod is offline   Reply With Quote
Old May 22nd, 2002, 02:22 PM   #3
Noir
 
Join Date: Mar 2002
Posts: 364
Default

Dimrod,
Thanks for your reply!

I may be doing something wrong but, the code is doing the exact same thing. It only highlights a portion of the serial numbers.

Also, what does, "Your code to enter the formula should be
Range([A2], [A65536].End(xlUp)).Offset(0, 2).Formula = "=IF(COUNTIF(Sheet2!R2C1:Sheet2!R3000C1,RC[-2])<>0,""Yes"",1)" mean? Did i need to do something special with this line of code? I just took the long code and placed it into a standard module. Did i need to place it somewhere else?

Thx,
Noir


Noir is offline   Reply With Quote
Old May 22nd, 2002, 03:16 PM   #4
Nimrod
MrExcel MVP
 
Join Date: Apr 2002
Location: Vancouver BC , Canada
Posts: 6,259
Default

This is a modification of the VBE help example for the find command. I've modified it so that it looks at values on Sheet 2 then highligts the same value on sheet1...if found there.
Does this help ?
Nimrod is offline   Reply With Quote
Old May 22nd, 2002, 03:16 PM   #5
Nimrod
MrExcel MVP
 
Join Date: Apr 2002
Location: Vancouver BC , Canada
Posts: 6,259
Default

This is a modification of the VBE help example for the find command. I've modified it so that it looks at values on Sheet 2 then highligts the same value on sheet1...if found there.
Does this help ?
Code:
Public Sub FindDuplicates()
For RwCnt = 1 To (Worksheets(2).Cells(65536, 1).End(xlUp).Row)
  SrchValue = Worksheets(2).Cells(RwCnt, 1).Value
        If Len(Trim(SrchValue)) > 0 Then
        With Worksheets(1).Range("a1:a" & (Cells(65536, 1).End(xlUp).Row))
            Set c = .Find(SrchValue, LookIn:=xlValues, Lookat:=xlWhole)
            If Not c Is Nothing Then
                firstAddress = c.Address
                Do
                    c.Interior.ColorIndex = 6
                    Set c = .FindNext(c)
                Loop While Not c Is Nothing And c.Address <> firstAddress
            End If
        End With
        End If
Next RwCnt
End Sub
Nimrod is offline   Reply With Quote
Old May 22nd, 2002, 03:47 PM   #6
Noir
 
Join Date: Mar 2002
Posts: 364
Default

Yes, the new version worked GREAT!!

Thanks Nimrod!
Noir
Noir is offline   Reply With Quote
Old May 22nd, 2002, 09:24 PM   #7
dimrod
 
Join Date: May 2002
Posts: 73
Default

Quote:
On 2002-05-22 09:22, Noir wrote:
Dimrod,
Thanks for your reply!

I may be doing something wrong but, the code is doing the exact same thing. It only highlights a portion of the serial numbers.

Also, what does, "Your code to enter the formula should be
Range([A2], [A65536].End(xlUp)).Offset(0, 2).Formula = "=IF(COUNTIF(Sheet2!R2C1:Sheet2!R3000C1,RC[-2])<>0,""Yes"",1)" mean? Did i need to do something special with this line of code? I just took the long code and placed it into a standard module. Did i need to place it somewhere else?

Thx,
Noir



Glad to see you got some code that does what you want.

However, just for the record, your macro works with the amendment to the line that enters the formula.

Can't think what you were doing wrong.

If you want to see what the amendment did, step through the code before and after the amendment, and have a look at the formula on the worksheet.


dimrod 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 +1. The time now is 05:46 AM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
All contents Copyright 1998-2009 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