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 Mar 16th, 2003, 05:30 PM   #1
James
 
Join Date: Feb 2002
Location: Huntington Beach, CA USA
Posts: 327
Default having a problem finding a solution

Hello all,

I have posted this question to two other boards, some of you may have seen it. I have done a search on the boards w/ no sucess. Simply, what is the vba code to read a Column and check for duplicates in that column.

i.e. with sheet"Invoice" commandbutton click copies the info to sheet "summary". Problem, every time the commandbutton is clicked it creates an error "a duplicate entry". I want to inform the enduser w/ a MsgBox that they have created a duplicate entry.

Any help on this subject would be greatly appreciated.

Regards
James
James is offline   Reply With Quote
Old Mar 16th, 2003, 06:12 PM   #2
phantom1975
MrExcel MVP
 
phantom1975's Avatar
 
Join Date: Jun 2002
Location: Omaha, Nebraska
Posts: 3,909
Default

Give this a whirl:

Code:
Private Sub CommandButton1_Click()
Dim MyColl As New Collection
Dim ThisCell As Range
Dim SearchCol As Range
Dim r As Integer
    On Error Resume Next
    r = 1
    Set SearchCol = Sheets("Sheet1").Range("C1:C100")
    For Each ThisCell In SearchCol
        If ThisCell.Value <> "" Then
            MyColl.Add ThisCell.Value, ThisCell.Value
            End If
        If Err.Number <> 0 Then
            If MsgBox("You have a duplicate entry in cell " & ThisCell.Address & ".  Do you wish to delete it?", vbYesNo + vbCritical, "Duplicate Entry") = vbYes Then
                ThisCell.ClearContents
                End If
        Else
            Sheets("Sheet2").Range("A" & r).Value = ThisCell.Value
            r = r + 1
            End If
        Err.Clear
        Next ThisCell
End Sub
__________________
Silly Billy was here....

***************** EXCEL/VB NEWBIES ARE MY FAVORITE! *****************
phantom1975 is offline   Reply With Quote
Old Mar 16th, 2003, 06:26 PM   #3
XL-Dennis
 
XL-Dennis's Avatar
 
Join Date: Jul 2002
Location: Östersund, Sweden
Posts: 1,917
Default

Hi James,

Quote:
I have posted this question to two other boards, some of you may have seen it.
Yes.... I dislike cross-posting very much and I don't help with this kind of post at all. :x :x
__________________
Kind regards,
Dennis

ExcelKB | .NET & Excel | 2nd edition PED
XL-Dennis is offline   Reply With Quote
Old Mar 16th, 2003, 06:32 PM   #4
phantom1975
MrExcel MVP
 
phantom1975's Avatar
 
Join Date: Jun 2002
Location: Omaha, Nebraska
Posts: 3,909
Default

I understand how frustrating it can be when you need help and find that you just can't get it. I will honestly tell you that this board really has some of the most talented people you will ever find that freely offer their experience and knowledge. XL-Dennis certainly being one of the most admired and talented people in my mind. I certainly invite you to use every resource you can to get the help and knowledge you need, however, I think you will find that your frustrations will be well resolved when you post here.
__________________
Silly Billy was here....

***************** EXCEL/VB NEWBIES ARE MY FAVORITE! *****************
phantom1975 is offline   Reply With Quote
Old Mar 16th, 2003, 07:14 PM   #5
James
 
Join Date: Feb 2002
Location: Huntington Beach, CA USA
Posts: 327
Default

Dennis,

I posted to a "help Forum" not an attitude / your opinion
forum if you have a problem w/ someone posting to differant forums looking for help/ a solution, and don't want to help....so be it. I don't care if you choose not to help me. It's Mr. Excel not xldennis.

Oh please Dennis forgive me , I promise you I will only post to this board and this board only.

Regards,
james
James is offline   Reply With Quote
Old Mar 16th, 2003, 07:43 PM   #6
James
 
Join Date: Feb 2002
Location: Huntington Beach, CA USA
Posts: 327
Default

Thanks Phantom,

I tried your code, adjusted the sheet names and column range. It didn't seem to work? Thanks for taking the to to help.

Regards
James
James is offline   Reply With Quote
Old Mar 16th, 2003, 08:17 PM   #7
Tom Urtis
MrExcel MVP
 
Tom Urtis's Avatar
 
Join Date: Feb 2002
Location: San Francisco, California USA
Posts: 9,626
Default

James --

Hello to a fellow Californian.

Not trying to step on Phantom's assistance, but can I ask please, what are you trying to actually achieve? Do you only want to know if a value you add from the Invoice list to the Summary list is a duplicate of one that already exists in the Summary list? Or do you want code that will check first if that "about-to-be-copied" value is a duplicate, and not copy it after all into the Summary list?

You have plenty of options but if you could please give a bit more detail about what you want, maybe outlining it as "if this is the case do this; if that is the case do that", I am sure we could find a solution that would help reach your objective.

Try to specify what you actually want to have happen if a duplicate is found. Example, do you want the user to have the option of copying the value anyway? Or do you want to disallow the copying and just provide a message box telling the user that the value already exists and the macro will not copy it?

Thanks.
__________________
Tom Urtis
Tom Urtis is offline   Reply With Quote
Old Mar 16th, 2003, 08:36 PM   #8
James
 
Join Date: Feb 2002
Location: Huntington Beach, CA USA
Posts: 327
Default

Hello Tom,

The commandbutton on sheet"Invoice" upon click copies and paste the info to sheet"summary". If the end
user for whatever reason clicks on the commandbutton
more than once would create a duplicate entry(s). What I'm trying to acheive is some bit of code that upon commandbutton click would check sheet "summary"
column f and if it finds a match would show the MsgBox
stating so....and what I was thinking instead of deleteing
the duplicate automatically, on click of say O.K. activate sheet"summary" and allow the end user to decide if they want to delete the entry or leave it.

Thanks for taking the time, appreciated

Regards
James
James is offline   Reply With Quote
Old Mar 16th, 2003, 08:40 PM   #9
Tom Urtis
MrExcel MVP
 
Tom Urtis's Avatar
 
Join Date: Feb 2002
Location: San Francisco, California USA
Posts: 9,626
Default

OK, two more follow-up questions:

(1)

You wrote:

"The commandbutton on sheet"Invoice" upon click copies and paste the info to sheet"summary". "

Is the code attached to your command button meant to copy an entire list in a range of cells, or just one cell...what is the nature of "the info" being copied?

(2)
What are the possible involved row-and-column ranges on each sheet?
__________________
Tom Urtis
Tom Urtis is offline   Reply With Quote
Old Mar 16th, 2003, 08:47 PM   #10
James
 
Join Date: Feb 2002
Location: Huntington Beach, CA USA
Posts: 327
Default

Hello Tom,

I'm creating this application for my neighbor to automate his invoicing. I've been at this since 4:30 A.M. our time, and I'm beat. Would you mind if I e- you the file?

Regards
James
James 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:25 AM.


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