Consulting

Results 1 to 3 of 3

Thread: Highlighting Duplicate numbers in excel only when they are next to each other

  1. #1

    Solved: Highlighting Duplicate numbers in excel only when they are next to each other

    I have a table that I want to either want to filter or copy the duplicates to a new worksheet when there is duplicate data in a certain column but only when they are next to each other. For example the 6112 026874784 is the same but I only care when they are next to each other :

    Materials 6112 026874784 American International Group, Inc.
    Financials 6118 591708102 MetroPCS Communications, Inc.
    Financials 6119 756577102 Red Hat, Inc.
    Materials 6112 026874784 American International Group, Inc.
    Materials 6112 026874784
    American International Group, Inc.

    I tried a custom filter but it show all of the cells that have more than one
    one in the column and I only care if they are next to each other. Thanks!

    [vba]Range("G:G").Select
    Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
    "=COUNTIF(G:G,G1)>1"
    Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriori ty
    With Selection.FormatConditions(1).Interior
    .PatternColorIndex = xlAutomatic
    .Color = 49407
    .TintAndShade = 0
    End With
    [/vba]
    Last edited by plawrenz; 06-18-2010 at 02:45 PM.

  2. #2
    Moderator VBAX Guru Simon Lloyd's Avatar
    Joined
    Sep 2005
    Location
    UK
    Posts
    3,003
    Location
    Does this do what you need?
    [VBA]Sub copy_duplicates()
    Dim i As Long
    For i = Sheets("Sheet1").Range("G" & Rows.Count).End(xlUp).Row To 2 Step -1
    If Sheets("Sheet1").Range("G" & i).Value = Sheets("Sheet1").Range("G" & i - 1).Value Then
    Sheets("Sheet1").Rows(i - 1 & ":" & i).Copy Destination:=Sheets("Sheet2").Range("A" & Rows.Count).End(xlUp).Offset(1, 0)
    End If
    Next i
    End Sub[/VBA]
    Regards,
    Simon
    Please read this before cross posting!
    In the unlikely event you didn't get your answer here try Microsoft Office Discussion @ The Code Cage
    If I have seen further it is by standing on the shoulders of giants.
    Isaac Newton, Letter to Robert Hooke, February 5, 1675 English mathematician & physicist (1642 - 1727)

  3. #3
    Yep that worked! Thanks so Much!!!!!

Posting Permissions

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