+ Reply to Thread
Results 1 to 26 of 26

Set value of cell to that of duplicate

  1. #1
    Registered User
    Join Date
    05-14-2017
    Location
    Stuttgart, Germany
    MS-Off Ver
    Ecel 2007
    Posts
    18

    Set value of cell to that of duplicate

    Hello!

    With some help on here I got the below code.
    It searched for duplicates and marks the entire row with the colour of the first instance.
    I, however, Need to do sth different but I can't figure out how.

    Instead of colouring, I Need row P to get a number which is unique for every set of duplicates, and each duplicate Needs to get the number of the first instance in row P.
    How can I Change this code do so?
    As it is it gets the value of the duplicate and puts it the cell but I Need it to get the num of the first instance and insert it into the new cell.
    I'd really appreciate any help whatsoever.

    Please Login or Register  to view this content.

  2. #2
    Forum Expert p24leclerc's Avatar
    Join Date
    07-05-2010
    Location
    Québec
    MS-Off Ver
    Excel 2021
    Posts
    2,081

    Re: Set value of cell to that of duplicate

    can you attach your workbook?
    Pierre Leclerc
    _______________________________________________________

    If you like the help you got,
    Click on the STAR "Add reputation" icon at the bottom.

  3. #3
    Registered User
    Join Date
    05-14-2017
    Location
    Stuttgart, Germany
    MS-Off Ver
    Ecel 2007
    Posts
    18

    Re: Set value of cell to that of duplicate

    Quote Originally Posted by p24leclerc View Post
    can you attach your workbook?
    I have attached an extract of it as it's way to big. I've manually put in numbers in the last column as example, please note the group marked in red as those are sort of a "special" case. Thanks in advance!
    Attached Files Attached Files

  4. #4
    Forum Expert p24leclerc's Avatar
    Join Date
    07-05-2010
    Location
    Québec
    MS-Off Ver
    Excel 2021
    Posts
    2,081

    Re: Set value of cell to that of duplicate

    your macro looks to a range from K2:N???.
    can you attach a workbook with as many columns as your macro uses so we can test the actual macro.
    We need your exact same structure you work with.
    Also, as your variable myrng covers 4 columns (K,L,M and N) the results will be written to 4 columns (O,P,Q and R). Am I right?
    Last edited by p24leclerc; 05-21-2017 at 09:34 PM.

  5. #5
    Registered User
    Join Date
    05-14-2017
    Location
    Stuttgart, Germany
    MS-Off Ver
    Ecel 2007
    Posts
    18
    Quote Originally Posted by p24leclerc View Post
    your macro looks to a range from K2:N???.
    can you attach a workbook with as many columns as your macro uses so we can test the actual macro.
    We need your exact same structure you work with.
    Also, as your variable myrng covers 4 columns (K,L,M and N) the results will be written to 4 columns (O,P,Q and R). Am I right?
    That's correct, i forgot to change that, i removed unnecessary columns. It should look through C to F, the last for columns with telephone numbers and email addresses. The results should be written to the next free column, so everything in one column. What I have isn't doing what it's meant to do, that's where i need help.

  6. #6
    Forum Expert p24leclerc's Avatar
    Join Date
    07-05-2010
    Location
    Québec
    MS-Off Ver
    Excel 2021
    Posts
    2,081

    Re: Set value of cell to that of duplicate

    try this modified macro.
    note that I added a title in G1 so the macro knows where to put the numbers.
    The macro actually search for the last used column which should be DUP.
    I found a problem as if you have a duplicate email address but the phone numbers are different, it will change the reference number of only one of them.
    This is happening for the email [email protected] which is in cell F233. This email is used by a precedent duplicate phone number (0151 1965908137) in row 112
    which happen to already have the reference number 1. You'll see that in cell H233, the reference number is 4 and that you only have 1 of this reference number.
    Please Login or Register  to view this content.
    You could put the reference numbers in different columns (one for each of C,D,E and F).
    What do you think?

  7. #7
    Registered User
    Join Date
    05-14-2017
    Location
    Stuttgart, Germany
    MS-Off Ver
    Ecel 2007
    Posts
    18
    Quote Originally Posted by p24leclerc View Post
    try this modified macro.
    note that I added a title in G1 so the macro knows where to put the numbers.
    The macro actually search for the last used column which should be DUP.
    I found a problem as if you have a duplicate email address but the phone numbers are different, it will change the reference number of only one of them.
    This is happening for the email [email protected] which is in cell F233. This email is used by a precedent duplicate phone number (0151 1965908137) in row 112
    which happen to already have the reference number 1. You'll see that in cell H233, the reference number is 4 and that you only have 1 of this reference number.
    Please Login or Register  to view this content.
    You could put the reference numbers in different columns (one for each of C,D,E and F).
    What do you think?
    Putting reference numbers in different columns won't really work as it's a way of sorting. I intend on then using the column with the reference numbers as a sorting column, say in ascending order. That's why they need to be in the same column and have the same number. The thing with the email is tricky, but since it's all one group it should ideally have the same reference number.

    Or is there a way of writing a macro that gives all entries with the same colour the same reference in a certain column? This way I could use the first macro which works with colours then run the second macro.

  8. #8
    Forum Expert p24leclerc's Avatar
    Join Date
    07-05-2010
    Location
    Québec
    MS-Off Ver
    Excel 2021
    Posts
    2,081

    Re: Set value of cell to that of duplicate

    Test this macro. It should take care of the above problem
    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    05-14-2017
    Location
    Stuttgart, Germany
    MS-Off Ver
    Ecel 2007
    Posts
    18

    Re: Set value of cell to that of duplicate

    Quote Originally Posted by p24leclerc View Post
    Test this macro. It should take care of the above problem
    Please Login or Register  to view this content.
    Thanks for taking your time to help me out!!!

    I haven't been able to test the code, as I'm getting a runtime error-type mismatch in the line marked bold.
    Trying to find the error myself has proven almost impossible as I am still trying to understand the code.

  10. #10
    Forum Expert p24leclerc's Avatar
    Join Date
    07-05-2010
    Location
    Québec
    MS-Off Ver
    Excel 2021
    Posts
    2,081

    Re: Set value of cell to that of duplicate

    you can try to make this small change although it works just fine on my computer.
    Please Login or Register  to view this content.
    Usually, a type mismatch means that you are trying to put like an alphanumeric data into an integer variable. Something like this.
    Just in case, are you sure your column where the reference numbers are written are empty.
    Maybe you have something else (like alphanumeric data ) in this column.

    Also, you can change
    Please Login or Register  to view this content.
    this way, it will accept any type of data.

  11. #11
    Registered User
    Join Date
    05-14-2017
    Location
    Stuttgart, Germany
    MS-Off Ver
    Ecel 2007
    Posts
    18

    Re: Set value of cell to that of duplicate

    Could you post what the results look like on your computer?
    It won't work on my computer.
    Also I undertook the aforementioned changes, it then runs but puts 1 in the first 15 columns of F or so and replaces the email addresses.

  12. #12
    Forum Expert p24leclerc's Avatar
    Join Date
    07-05-2010
    Location
    Québec
    MS-Off Ver
    Excel 2021
    Posts
    2,081

    Re: Set value of cell to that of duplicate

    here it is.
    Attached Files Attached Files

  13. #13
    Registered User
    Join Date
    05-14-2017
    Location
    Stuttgart, Germany
    MS-Off Ver
    Ecel 2007
    Posts
    18

    Re: Set value of cell to that of duplicate

    Great! If only it'd work on my PC as well.
    It's got to run on PC set to German, and from looking around the culture could be the problem.
    What is the culture of your PC?
    Is there a way to manipulate the code to work on different cultures?

  14. #14
    Forum Expert p24leclerc's Avatar
    Join Date
    07-05-2010
    Location
    Québec
    MS-Off Ver
    Excel 2021
    Posts
    2,081

    Re: Set value of cell to that of duplicate

    I've done macros for many countries around the workd and I never had such problem.
    But as this is the first time I use an Application.WorksheetFunction, there might be the problem.
    I think the only place in the code that could be sensitive to culture as you say is this:
    Please Login or Register  to view this content.
    Find in your Excel, what if the name used for this function and you should be Ok to run it.
    If you type in your VBE the beginning of the code (like: Application.worksheetFunction.) it should give you a list of possible functions available.
    You should be able to find the German translation for COUNTIF. I found an Excel function translator and it give me ZÄHLENWENN for CountIf.
    Does it make sense?

  15. #15
    Forum Expert p24leclerc's Avatar
    Join Date
    07-05-2010
    Location
    Québec
    MS-Off Ver
    Excel 2021
    Posts
    2,081

    Re: Set value of cell to that of duplicate

    Forget about my remark about translating the Countif function.
    After testing on another computer with a french Excel, I can tell you that the CountIf function is the same in both system no matter which language is set up on the computer.
    As a matter of fact, both Excel (one in French and the other in English) uses the same english syntax to program in VBA. So, there must be something else in play.
    What is the error you are getting? At what line of code?

  16. #16
    Registered User
    Join Date
    05-14-2017
    Location
    Stuttgart, Germany
    MS-Off Ver
    Ecel 2007
    Posts
    18

    Re: Set value of cell to that of duplicate

    Run time error-type mismatch in
    Temp_Num = Cells(cell.Row, Last_col)
    I did too just realise that the CountIf function is the same in German as well.

  17. #17
    Registered User
    Join Date
    05-14-2017
    Location
    Stuttgart, Germany
    MS-Off Ver
    Ecel 2007
    Posts
    18

    Re: Set value of cell to that of duplicate

    Could the excel version be the problem? I'm using Excel 2010.

  18. #18
    Registered User
    Join Date
    05-14-2017
    Location
    Stuttgart, Germany
    MS-Off Ver
    Ecel 2007
    Posts
    18

    Re: Set value of cell to that of duplicate

    After debugging, I see temp_num has the value 0 which can't be right, but I don't know where to fix it.

  19. #19
    Registered User
    Join Date
    05-14-2017
    Location
    Stuttgart, Germany
    MS-Off Ver
    Ecel 2007
    Posts
    18

    Re: Set value of cell to that of duplicate

    Quote Originally Posted by infogirl96 View Post
    After debugging, I see temp_num has the value 0 which can't be right, but I don't know where to fix it.
    Temp_Num = Cells(cell.Row, Last_col) is then 87(long), and 6 (integer). They should both be integers, right?

  20. #20
    Forum Expert p24leclerc's Avatar
    Join Date
    07-05-2010
    Location
    Québec
    MS-Off Ver
    Excel 2021
    Posts
    2,081

    Re: Set value of cell to that of duplicate

    are your running the macro with the exact same file I supplied?
    If not, can you attached yours so I can check what goes wrong?
    You are right, both Num and Temp_Num should be the same.
    Try
    Please Login or Register  to view this content.

  21. #21
    Registered User
    Join Date
    05-14-2017
    Location
    Stuttgart, Germany
    MS-Off Ver
    Ecel 2007
    Posts
    18

    Re: Set value of cell to that of duplicate

    I made that change, but that didn't fix the issue.
    I did run it on exactly what I uploaded here, and it isn't working on other workbooks neither.

  22. #22
    Forum Expert p24leclerc's Avatar
    Join Date
    07-05-2010
    Location
    Québec
    MS-Off Ver
    Excel 2021
    Posts
    2,081

    Re: Set value of cell to that of duplicate

    I just tryied this workbook on my old XP computer running Excel 2010 and it runs perfectly.
    So the problem is on your computer set up or something like that.
    Can you try running it on an Excel 2013 or 2016 on another computer to see if it works at all?
    Have you tried to run it step by step and see what it does?

  23. #23
    Registered User
    Join Date
    05-14-2017
    Location
    Stuttgart, Germany
    MS-Off Ver
    Ecel 2007
    Posts
    18

    Re: Set value of cell to that of duplicate

    I have tried on 2 computers, one running windows 7 and the other windows 10, both returning the same error. The latter has Excel 2016 and it isn't working there either.
    But strangely enough producing the same error at the same place on both, F87. Both computers are however set to German, that may be the problem, I don't know really..

  24. #24
    Forum Expert p24leclerc's Avatar
    Join Date
    07-05-2010
    Location
    Québec
    MS-Off Ver
    Excel 2021
    Posts
    2,081

    Re: Set value of cell to that of duplicate

    I think I finally found the problem. You are doing your test on your original workbook, aren't you?
    On the workbook I attached, You'll see that I added 2 titles in row 1. Column G = ??? and Column H = DUP
    When you run my macro on your original workbook, the Last_Col variable is set to 6 as you stated in one of your post. Column 6 being F which contains e-mail addresses.
    With my modification of the titles, the Last_Col variable has the value of 8 which is column H where we want to put the duplicate number.
    Column G contains alpha data whcih causes the error. Column H contains intergers and should not cause any error.
    Either upload my workbook or do the modification to your title row (row 1) and every thing should work just fine.
    Sorry about this issue and all the time I took to realize it.

    If you want the numbering to start at number 1, then change this line of code
    Please Login or Register  to view this content.
    to
    Please Login or Register  to view this content.

  25. #25
    Registered User
    Join Date
    05-14-2017
    Location
    Stuttgart, Germany
    MS-Off Ver
    Ecel 2007
    Posts
    18

    Re: Set value of cell to that of duplicate

    Quote Originally Posted by p24leclerc View Post
    I think I finally found the problem. You are doing your test on your original workbook, aren't you?
    On the workbook I attached, You'll see that I added 2 titles in row 1. Column G = ??? and Column H = DUP
    When you run my macro on your original workbook, the Last_Col variable is set to 6 as you stated in one of your post. Column 6 being F which contains e-mail addresses.
    With my modification of the titles, the Last_Col variable has the value of 8 which is column H where we want to put the duplicate number.
    Column G contains alpha data whcih causes the error. Column H contains intergers and should not cause any error.
    Either upload my workbook or do the modification to your title row (row 1) and every thing should work just fine.
    Sorry about this issue and all the time I took to realize it.

    If you want the numbering to start at number 1, then change this line of code
    Please Login or Register  to view this content.
    to
    Please Login or Register  to view this content.
    That certainly was the problem, thank so much!!
    Out of curiousity, what is Column ??? needed for

  26. #26
    Forum Expert p24leclerc's Avatar
    Join Date
    07-05-2010
    Location
    Québec
    MS-Off Ver
    Excel 2021
    Posts
    2,081

    Re: Set value of cell to that of duplicate

    It was the duplicate number you wrote in the table as a desired result and to check with the result of the macro.
    The macro will automatically find the last column of your table. Just make sure this column is empty but for the title which can be anything.

+ 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] Code to check cell against a list for duplicate, if no duplicate, post to bottom of list..
    By wannabacat in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-28-2015, 11:42 AM
  2. [SOLVED] Combine rows with duplicate items in one cell and merge values in other cell
    By Niclal in forum Excel Programming / VBA / Macros
    Replies: 17
    Last Post: 09-18-2014, 07:04 AM
  3. Replies: 1
    Last Post: 06-01-2013, 01:27 AM
  4. [SOLVED] Delete rows based on duplicate cell, but leaving first and last duplicate.
    By LadyNicole in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-28-2013, 05:07 AM
  5. Replies: 5
    Last Post: 08-10-2012, 04:32 PM
  6. [SOLVED] Locating Duplicate Cell Data with a Cell Counter and Highlight
    By garrett.grillo in forum Excel General
    Replies: 1
    Last Post: 04-30-2012, 12:52 AM
  7. Replies: 1
    Last Post: 01-26-2012, 10:06 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