+ Reply to Thread
Results 1 to 2 of 2

Macro that will flag a duplicate line.

Hybrid View

  1. #1
    Registered User
    Join Date
    07-07-2014
    Location
    United States
    MS-Off Ver
    2010
    Posts
    30

    Macro that will flag a duplicate line.

    Hi,

    So I am curious if there is a code for a macro that will flag a duplicate line for me. For instance,

    A - B - C - D
    1 123 Yes Ops
    2 172 Yes Crt
    3 187 No Crt
    4 123 No Ops
    5 187 No Crt Duplicate
    6 172 No Ops
    7 123 Yes Ops Duplicate

    The macro (Or Formula if possible and easier) would flag any duplicate lines based on the Criteria in column A through C. I do not need the entire row to be identical, just three particular columns. In Addition, I would only want the second, third and so on tagged as a duplicate, not the original.

    Thanks,
    Justin

  2. #2
    Valued Forum Contributor ranman256's Avatar
    Join Date
    07-29-2012
    Location
    Kentucky
    MS-Off Ver
    Excel 2003
    Posts
    1,178

    Re: Macro that will flag a duplicate line.

    Here's my code from a more complex version...you can tweek it for your needs...

    Public Sub MarkDuplicates()    'ByVal pvQry, ByVal pvDupeFld, ByVal pvMarkFld, Optional ByVal pvFld2Check)
    'pvQry = query name
    'pvDupeFld   = field with duplicate values
    'pvMarkFld    = field to change when duplicate is found
    'pvFld2Check = field to check to see if 2nd fld different than the 1st one
    Dim vCurrDup, vPrevDup, vKey, vCurrFld, vAddr
    
    on error goto ErrDupe
    
    range("A1").select
    
       'set the duplicate info to search
    pvDupeFld = 3
    pvMarkFld = 5
    pvFld2Check = 2
            
    vPrevDup = "*&%"
    
    While activecell.value <> ""
            vCurrDup = activecell.offset(0,pvDupeFld).value
            vCurrFld = activecell.offset(0,pvFld2Check).value
            vKey =  activecell.offset(0,pvFld2Check).value         
            
            If vCurrDup <> "" Then
                    '-----------------------
                    'MARK THE DUPES...
                    '-----------------------
                  If vPrevDup = vCurrDup And vPrevFld = vCurrFld Then         'mark this
                        activecell.offset(0,pvMarkFld).value = "Delete"
                  End If
            End If
    
            vPrevDup = vCurrDup
            vPrevFld = vCurrFld
            
            activecell.offset(1,0).select   'next row
    Wend
    Exit Sub
    ErrDupe:
    MsgBox Err.Description, , "MarkDuplicates():" & Err
    End Sub

+ 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. Macro to Duplicate Line + Transpose Data
    By flarel in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-28-2012, 05:07 AM
  2. [SOLVED] Macro to duplicate line
    By cossie2k in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 06-12-2012, 04:13 AM
  3. Flag if Duplicate
    By LottieCampbell in forum Excel General
    Replies: 3
    Last Post: 03-29-2012, 09:47 AM
  4. Macro to set Flag on dup values
    By carlysyme in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-27-2009, 09:16 AM
  5. [SOLVED] Macro problem on, Yellowed line - previous line or next line.
    By Ed in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 03-29-2005, 07:06 PM

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