+ Reply to Thread
Results 1 to 5 of 5

VBA code to find duplicate cells in a column, then perform a function

  1. #1
    Registered User
    Join Date
    05-16-2013
    Location
    US
    MS-Off Ver
    Excel 2010
    Posts
    10

    VBA code to find duplicate cells in a column, then perform a function

    Hello everyone!

    This is my first post and I'm somewhat new to excel VBA. Here we go....

    I have an excel sheet with numbers in column A. For instance:

    A1 = 1
    A2 = 2
    A3 = 3
    A4 = 2
    A5 = 1
    A6 = 2
    A7 = 5
    A8 = 2

    What I would like to do, for all cells in column A, is to find the instances of duplicate values, then perform a function in that row.

    The code would do nothing for A1, A2, A3, A7 because they are unique values.
    For A4, A5, A6, A8 (duplicates), the macro would then do another function in the same row. My coding is poor but the wording would look like this...."IF A4 appears in any cells above, THEN C4 = B4".

    Thanks for any help. Let me know if you need any further info.

    -Chris

  2. #2
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,516

    Re: VBA code to find duplicate cells in a column, then perform a function

    Is this what you mean?
    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    05-16-2013
    Location
    US
    MS-Off Ver
    Excel 2010
    Posts
    10

    Re: VBA code to find duplicate cells in a column, then perform a function

    Jindon,

    Thank you for the response. This is close, but I need to understand the code better to make it work. I see that your code identifies the proper cells in column A, but I need to adjust what it does after that.

    What can I manipulate within your code to perform various tasks in the row? Right now, I think it makes the A cell = B cell. What if I want to have D cell = B + C in that row?

    Thanks again

  4. #4
    Registered User
    Join Date
    05-16-2013
    Location
    US
    MS-Off Ver
    Excel 2010
    Posts
    10

    Re: VBA code to find duplicate cells in a column, then perform a function

    Sorry, I tried to generalize the problem in my first post but here is exactly what I want to do....


    PHP Code: 
    Range("A2").Select
    Range
    (SelectionSelection.End(xlDown)).Select
    Dim x 
    As Range
     
     
    For Each x In Selection
      
    If Countif(Range"all values above x""x") > 1 Then
      x
    .Offset(0,7) = x.Offset(0,7) - x.Offset(0,8)
      
    x.Offest(0,8) = 0
      End 
    If
     
    Next x 
    Obviously this doesnt work, but it is a basic code of what I described in my first post.
    Last edited by under00c; 06-07-2013 at 08:21 AM. Reason: Wrap code with code tag

  5. #5
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,516

    Re: VBA code to find duplicate cells in a column, then perform a function

    I don't think I understand what you are trying to do, so please wait for someone else to come in to help you.

    By the way, You need to edit your last post and wrap the code with the code tag.

    It's a forum rule.

+ 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