+ Reply to Thread
Results 1 to 5 of 5

VBA code that checks column A for values that are duplicates.

  1. #1
    Registered User
    Join Date
    11-19-2022
    Location
    Manchester, UK
    MS-Off Ver
    365
    Posts
    6

    VBA code that checks column A for values that are duplicates.

    Hello,

    I have a userform and when I submit, a record is added to a spreadsheet called "CallData", every record should ideally have a unique record under "CustomerID".

    Here is an example:

    Customer ID
    12345
    14785
    12345
    68996
    45666
    12345

    Each record has multiple other rows, I do not want to overwrite the first record of "12345" when I am adding it again due to dealing with the same customer, each record is an interaction and should be individually added.

    I would like to upon submitting a new record, if it's a duplicate, add a unique string onto the end to ensure I am not overwriting these records, for example "12345-1", if the same customer appears in the future, I add this "interaction", the Customer ID would be "12345-2" and so on.

    I would then want to be able to retrieve the record of "12345" by populating the list box with all results that include "12345", those that have "-1", "-2" etc.. on the end

    Can someone suggest a way to with VBA:
    1: Upon submitting customer record, if CustomerID exists, add "-1", "-2" etc.. to the end
    2: Populate the list box with the references corresponding to "12345" that is typed into a text box (and the duplicates)


    Thanks
    Will.

  2. #2
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,947

    Re: VBA code that checks column A for values that are duplicates.

    Allow duplicates in column A, but add a new column B with formulas like

    =COUNTIF($A$2:A2,A2)

    or

    =A2 & "-" & COUNTIF($A$2:A2,A2)

    and that will add the transaction number for the customer ID. Then you can just filter A as normal.
    Bernie Deitrick
    Excel MVP 2000-2010

  3. #3
    Registered User
    Join Date
    11-19-2022
    Location
    Manchester, UK
    MS-Off Ver
    365
    Posts
    6

    Re: VBA code that checks column A for values that are duplicates.

    Quote Originally Posted by Bernie Deitrick View Post
    Allow duplicates in column A, but add a new column B with formulas like

    =COUNTIF($A$2:A2,A2)

    or

    =A2 & "-" & COUNTIF($A$2:A2,A2)

    and that will add the transaction number for the customer ID. Then you can just filter A as normal.
    Thanks for that,

    would it be safe to add this to the far right of the spreadsheet? So that I could then update my VBA code so when it's updating a record its based on that transaction number, and at the same time I don't have to edit all the code to reflect everything bumped forward a column.

  4. #4
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,209

    Re: VBA code that checks column A for values that are duplicates.

    Yes .. you can put the COUNTIF in any column.
    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED.

  5. #5
    Registered User
    Join Date
    11-19-2022
    Location
    Manchester, UK
    MS-Off Ver
    365
    Posts
    6

    Re: VBA code that checks column A for values that are duplicates.

    Thanks, simple and effective, I now won't risk editing the wrong interaction.

+ 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] Crafting an IF statement that checks multiple values in one column
    By garethlittle in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 02-26-2020, 07:28 AM
  2. [SOLVED] Trying to use .Find to create a column of values with no duplicates. Code not working.
    By unit285 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 04-13-2019, 08:09 AM
  3. Finding duplicates in column A and checks column B if corresp value exceed total
    By edsel1979 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-19-2015, 09:01 AM
  4. Code that checks the last day of a month in a rollbook and returns values
    By Rob.Marchel in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 09-01-2014, 09:01 PM
  5. [SOLVED] Find duplicates in column A, add values from column B (possibly delete duplicates)
    By luarwhite in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-12-2013, 04:34 PM
  6. Need a code that checks a column of dates, and then copies the row
    By astropopostar in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-05-2012, 12:29 AM

Tags for this Thread

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