+ Reply to Thread
Results 1 to 7 of 7

Find duplicated value by comparing textbox and column

  1. #1
    Registered User
    Join Date
    12-03-2014
    Location
    swe
    MS-Off Ver
    office 2010
    Posts
    57

    Find duplicated value by comparing textbox and column

    Hi

    Pls refer to my uploaded example file.

    I have a table where i want to make sure no duplicated values can be posted in the B column.
    I have a userform that is used to add data to the table.

    However, i can not prevent a value from being added since my current code is checking if there are
    duplicated values in the column only.

    I want to check if the value that I have typed in the textbox is to be found in the B column before the code
    that creates the new row and saves the data to the table is being triggerd.

    Here are my two codes

    1. Add row to table from userform textboxes
    2. Check for duplicates in the B column and print all found duplicated values in a msgbox

    Please Login or Register  to view this content.
    Attached Files Attached Files

  2. #2
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,482

    Re: Find duplicated value by comparing textbox and column

    Probably using the textbox exit would do the trick....
    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    12-03-2014
    Location
    swe
    MS-Off Ver
    office 2010
    Posts
    57

    Re: Find duplicated value by comparing textbox and column

    It does not work to have it in the exit part of the textbox.

    I forgot to mention that i also use the same userform (in my real document, not example)
    to view data, so the the duplicate code in exit of the textbox would not work since it would detect its own row.


    it would be much better if i could get this code to work
    Please Login or Register  to view this content.
    but it keeps displaying the msgbox as duplicates even if there are none in the column

  4. #4
    Registered User
    Join Date
    12-03-2014
    Location
    swe
    MS-Off Ver
    office 2010
    Posts
    57

    Re: Find duplicated value by comparing textbox and column

    forgot to mention that i have declared the "newdupdetected at the top of the module as "public newdupdetected as integer"

  5. #5
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,613

    Re: Find duplicated value by comparing textbox and column

    Please Login or Register  to view this content.
    Ben Van Johnson

  6. #6
    Registered User
    Join Date
    12-03-2014
    Location
    swe
    MS-Off Ver
    office 2010
    Posts
    57

    Re: Find duplicated value by comparing textbox and column

    Thats great
    It works wonders in my example file.
    But i can for my life not move it over to my original document.

    I get errors on this row
    "incompatible types"
    Please Login or Register  to view this content.
    I do try to put it in a module and call for it from the save button.
    is that it?


    edit 2:

    ok i think i got it...
    but dont know how to fix it.

    it works if i have numbers as the data values in the textboxes
    but it does not work with letters.

    how to make it search for everything?


    edit:
    i disabled some parts of the code
    so this is what it looks like
    what am i doing wrong and why do i get above error message?

    Please Login or Register  to view this content.
    Last edited by behedwin; 01-14-2017 at 05:22 AM.

  7. #7
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,613

    Re: Find duplicated value by comparing textbox and column

    In the sample workbook you only had numbers in column B, not letters. Assuming all textbox data would be digits, I used CLNG() to convert them to numeric.
    The mod below will test to see if the textbox text can be evaluated as a number and convert them or just pass any letter values on.
    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Find a value in a column in the entire workbook and ad it into a Textbox
    By RinorM in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 12-30-2014, 07:29 AM
  2. [SOLVED] Find a value in a column in the entire workbook and ad it into a Textbox
    By RinorM in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 12-30-2014, 03:17 AM
  3. Find a value in a column in the entire workbook and ad it into a Textbox
    By RinorM in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-29-2014, 10:22 AM
  4. Replies: 5
    Last Post: 05-14-2014, 08:35 AM
  5. [SOLVED] Find the last cell with value in column E and Send value of textbox to the same row in col
    By MariaPap in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 12-24-2013, 12:15 PM
  6. [SOLVED] find the highest value in a column and in a textbox
    By marreco in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-13-2013, 11:42 AM
  7. Replies: 0
    Last Post: 09-25-2012, 03:42 PM

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