+ Reply to Thread
Results 1 to 4 of 4

Modifying Existing Code to Check if the entry exists

  1. #1
    Registered User
    Join Date
    07-22-2010
    Location
    Ontario
    MS-Off Ver
    Excel 2003
    Posts
    71

    Modifying Existing Code to Check if the entry exists

    Hi There,

    I need your help,

    I have a code below that works well with a userform that adds my data from my userform to an excel worksheet. It works great and all, but id like to modify it to have it check and see if the file number (fn) exists before writting it back to the worksheet, if it exists, then msgbox "Error: Record Cannot be added - (Duplicate Entry)" and do nothing else, if the file number does not exist, proceed as normal and execute the rest of the code.

    Please Login or Register  to view this content.
    Any help with this is greatly appreciated.

    Much thanks for all your help in advance.

    Thanks,

    Jay
    Last edited by jason_kelly; 12-31-2010 at 10:39 AM.

  2. #2
    Forum Expert Mordred's Avatar
    Join Date
    07-06-2010
    Location
    Winnipeg, Canada
    MS-Off Ver
    2007, 2010
    Posts
    2,787

    Re: Modifying Existing Code to Check if the entry exists

    Couldn't you just run an If statement like:
    Please Login or Register  to view this content.
    Mayhap I am over simplifiing the matter.
    If you're happy with someone's help, click that little star at the bottom left of their post to give them Reps.

    ---Keep on Coding in the Free World---

  3. #3
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,431

    Re: Modifying Existing Code to Check if the entry exists

    As Mordred suggests you can compare the variable to the cell before populating it.

    You can also reduce the duplication in your code by simply assigning the reference to the correct worksheet before transferring values.

    I have assumed if the value already exists then no information is transferred

    Please Login or Register  to view this content.
    Cheers
    Andy
    www.andypope.info

  4. #4
    Registered User
    Join Date
    07-22-2010
    Location
    Ontario
    MS-Off Ver
    Excel 2003
    Posts
    71

    Re: Modifying Existing Code to Check if the entry exists

    Thanks very much all for the wonderful help!

    Worked like a charm.

    Cheers,

    Jay

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1