Consulting

Results 1 to 5 of 5

Thread: identifying duplicates on each row

  1. #1
    VBAX Regular
    Joined
    Jun 2018
    Posts
    42
    Location

    identifying duplicates on each row

    Hi all,

    I was wondering if someone can help me with some code.

    For each row i'm trying to identifying if the values of 2 cells is the same as the following 2 cells and highlight them. Example below, any help would be much appreciated

    11111111111.jpg
    Attached Files Attached Files

  2. #2
    VBAX Mentor 大灰狼1976's Avatar
    Joined
    Dec 2018
    Location
    SuZhou China
    Posts
    479
    Location
    Hi CJW_14!
    Something like below:
    Sub test()
    Dim clm&, rng As Range, i&, j&
    For i = 4 To [e65536].End(3).Row
      clm = Cells(i, 16384).End(1).Column - 3
      For j = 5 To clm Step 2
        If Cells(i, j) = Cells(i, j + 2) And Cells(i, j + 1) = Cells(i, j + 3) Then
          If rng Is Nothing Then
            Set rng = Cells(i, j).Resize(, 4)
          Else
            Set rng = Union(rng, Cells(i, j).Resize(, 4))
          End If
        End If
      Next j
    Next i
    If not rng Is Nothing Then rng.Interior.Color = vbYellow
    End Sub

  3. #3
    VBAX Regular
    Joined
    Jun 2018
    Posts
    42
    Location
    You are a legend mate, thanks alot

  4. #4
    Knowledge Base Approver VBAX Wizard
    Joined
    Apr 2012
    Posts
    5,646
    Or

    Sub M_snb()
      Sheet1.Cells.UnMerge
      sn = Cells(3, 1).CurrentRegion
    
      For j = 3 To UBound(sn)
        For jj = 5 To UBound(sn, 2) - 4
          If sn(j, jj) & sn(j, jj + 1) = sn(j, jj + 2) & sn(j, jj + 3) And sn(j, jj) & sn(j, jj + 1) <> "" Then
            Sheet1.Cells(j + 1, jj).Resize(, 4).Interior.Colorindex = 6
            jj = jj + 4
          End If
        Next
      Next
    End Sub
    Or
    Sub M_snb()
        Sheet1.Cells.UnMerge
        sn = Cells(3, 1).CurrentRegion
        
        For j = 3 To UBound(sn)
           For jj = 5 To UBound(sn, 2) - 4
             If sn(j, jj) & sn(j, jj + 1) = sn(j, jj + 2) & sn(j, jj + 3) And sn(j, jj) & sn(j, jj + 1) <> "" Then
                c00 = c00 & "," & Cells(j + 1, jj).Resize(, 4).Address
                jj = jj + 4
             End If
           Next
        Next
    
        If c00 <> "" Then Sheet1.Range(Mid(c00, 2)).Interior.ColorIndex = 6
    End Sub


    NB. Always use row 1 & Column A !!
    Last edited by snb; 03-14-2019 at 02:47 AM.

  5. #5
    VBAX Regular
    Joined
    Jun 2018
    Posts
    42
    Location
    Thanks for the code snb, much appreciated

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •