+ Reply to Thread
Results 1 to 4 of 4

Adding a small perturbation to duplicate values in two columns

  1. #1
    Registered User
    Join Date
    10-21-2012
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    11

    Adding a small perturbation to duplicate values in two columns

    I have two columns of data as follows:

    Column A Column B
    49 49
    49 49
    49 49
    50 50
    51 51
    51 51
    51 51
    51 51
    52 52
    52 52
    52 52
    53 53

    I would like to write a script that adds +0.0001 to each value that is duplicated in column A. For example, for the three 49 values in column A, it would generate a new column with values as follows 49, 49.001, 49.002. Then for 50, it would not add +.0001 but would ad it to the 51 values (51, 51.001, 51.002, 51.003) and continue this pattern.

    For column B, the exact same process should occur, expect -0.0001 is added to each value, therefore the for the three 49 values in column B would generate a new column with values, 49, 48.999, 48.998, 48.997

    What would be the best approach to take for this?

    Thank you for your help

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Adding a small perturbation to duplicate values in two columns

    How about just a formula?

    In C1 and copy down,

    =A1 + 0.001*(countif(A$1:A1, A1) - 1)
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Registered User
    Join Date
    10-21-2012
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    11

    Re: Adding a small perturbation to duplicate values in two columns

    Thank you, the formula works but i have a data set of over 20,000 cells. I am looking to automate the process with a script.

  4. #4
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    53,051

    Re: Adding a small perturbation to duplicate values in two columns

    I would have offered the same suggestion as shg. you can always value the helper column over to the original data when you are finished, and then delete the helper
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

+ 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