+ Reply to Thread
Results 1 to 5 of 5

finding duplicate column D

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    08-08-2012
    Location
    london
    MS-Off Ver
    Excel 2010
    Posts
    196

    finding duplicate column D

    hi,

    I am trying to get the following macro, to read column D and highlight any rows, which contain duplicate cells from column D.

    Please view the attachment for further details, as to what the output should look like, when there is duplicate in column D.
    test1.xlsx

    The below code is throwing back a run-time error 9. I am little unclear what is causing this behavior.
    Please advice further, if possible.

    Sub test()
    Dim rng As Range, c As Range, cfind As Range, rng1 As Range
    Worksheets("room list").Activate
    Set rng = Range(Range("D2"), Range("D2").End(xlDown))
    Set rng1 = Range(Range("B2"), Range("B2").End(xlDown))
    
    For Each c In rng
    Set cfind = rng1.Cells.Find(what:=c.Value, lookat:=xlWhole)
    If Not cfind Is Nothing Then c.Interior.ColorIndex = 3
    Next c
    End Sub
    Many thanks

  2. #2
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,088

    Re: finding duplicate column D

    Try
    Option Explicit
    
    Sub test()
    Dim rng As Range, c As Range, cfind As Range, rng1 As Range
    With Worksheets("Room_list")
        Set rng = .Range("D2:D" & .Range("D" & Rows.Count).End(xlUp).Row)
    End With
    
        For Each c In rng
            If (Application.CountIf(rng, c.Value) >= 2) Then c.Interior.ColorIndex = 3
        Next c
    End Sub
    Attached Files Attached Files
    - Battle without fear gives no glory - Just try

  3. #3
    Forum Contributor
    Join Date
    08-08-2012
    Location
    london
    MS-Off Ver
    Excel 2010
    Posts
    196

    Re: finding duplicate column D

    Thank you very much for your great help. The code works great

    i would like to request, if it would be possible highlight the entire row, instead of the duplicate cells in column D.

    Thank you for your time & help.

  4. #4
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,088

    Re: finding duplicate column D

    See here

    Option Explicit
    
    Sub test()
    Dim rng As Range, c As Range, cfind As Range, rng1 As Range
    With Worksheets("Room_list")
        Set rng = .Range("D2:D" & .Range("D" & Rows.Count).End(xlUp).Row)
    End With
        For Each c In rng
            If (Application.CountIf(rng, c.Value) >= 2) Then c.EntireRow.Interior.ColorIndex = 3
        Next c
    End Sub
    Attached Files Attached Files

  5. #5
    Forum Contributor
    Join Date
    08-08-2012
    Location
    london
    MS-Off Ver
    Excel 2010
    Posts
    196

    Re: finding duplicate column D

    Thank you for updating the code. The macro works great.
    Thank you very much for all your help and time.

+ 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. finding duplicate content within a column
    By Excel_help in forum Excel General
    Replies: 7
    Last Post: 01-20-2015, 06:13 AM
  2. Finding partial duplicate values in the same column
    By cmax979 in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 10-09-2013, 06:11 PM
  3. Finding duplicate entries within a column
    By mazalam in forum Excel General
    Replies: 1
    Last Post: 08-29-2005, 04:56 PM
  4. Finding duplicate cell entries in a column of data
    By Ellie in forum Excel General
    Replies: 1
    Last Post: 07-28-2005, 09:05 AM
  5. Finding Duplicate values within a single column
    By Ed P in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-16-2005, 07:06 PM

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