Consulting

Results 1 to 8 of 8

Thread: Last Duplicate Value in Column

  1. #1
    VBAX Regular
    Joined
    May 2008
    Posts
    48
    Location

    Last Duplicate Value in Column

    How do you find the last duplicate value in a column?

    Column B
    BV
    Vertex
    ISO
    Regional
    BV
    BV <<<<<<<<<<< Need to find this value
    Overland
    Vertex <<<<<<<<<Need to find this value
    MUM
    IUM

  2. #2
    VBAX Tutor david000's Avatar
    Joined
    Mar 2007
    Location
    Chicago
    Posts
    276
    Location

    I'm not sure what the EXACT answer is.

    this would find the last anything filtered duplacates or whatever.


    [vba]Sub Macro1()
    Dim wk As Worksheet
    Dim LastRow As Long
    Dim LastCell As Range
    Set wk = ActiveSheet
    Application.ScreenUpdating = False
    On Error GoTo x_it:
    With wk
    LastRow = Range("c" & Rows.Count).End(xlUp).Row
    wk.Range("c2").Resize(LastRow - 1).ClearContents
    wk.Columns(2).AutoFilter
    wk.Range("$B$1").AutoFilter Field:=1, Criteria1:=Range("c1").Text


    Set LastCell = .Columns(2).Find( _
    What:="*", _
    After:=[B1], _
    LookIn:=xlValues, _
    lookat:=xlWhole, _
    SearchOrder:=xlByRows, _
    SearchDirection:=xlPrevious)
    If Not LastCell Is Nothing Then
    LastRow = LastCell.Row
    End If
    .Range("b" & LastRow).Offset(, 1) = "< last one here"
    End With
    wk.AutoFilterMode = False
    Application.ScreenUpdating = True
    Exit Sub
    x_it:
    Application.ScreenUpdating = True
    MsgBox Err.Description
    End Sub
    [/vba]

  3. #3
    Knowledge Base Approver VBAX Master Oorang's Avatar
    Joined
    Jan 2007
    Posts
    1,135
    Location
    Are you defining duplicate as any value that appears in a column more than once, or are you defining duplicate as any value that has an adjacent cell in the same column of the same value?
    Cordially,
    Aaron



    Keep Our Board Clean!
    • Please Mark your thread "Solved" if you get an acceptable response (under thread tools).
    • Enclose your code in VBA tags then it will be formatted as per the VBIDE to improve readability.

  4. #4
    VBAX Regular
    Joined
    May 2008
    Posts
    48
    Location
    I'm defining duplicate as any value that appears in a column more than once. Thank you




    I'm looking for a forumula that will place a value in Column F based on the value based on the the latest duplicate value in a column B
    Last edited by LOSS1574; 06-12-2008 at 11:36 AM.

  5. #5
    Knowledge Base Approver VBAX Master Oorang's Avatar
    Joined
    Jan 2007
    Posts
    1,135
    Location
    Since David has already posted code, I'll give you a non-code approach. Say you want to check out column A. Insert a blank column and in the top cell put =(COUNTIF($A$2:$A$21,A20)>1)*ROW()
    Then just filter to your top one item. (Click top ten and you will be prompted for a number other than 10).
    Cordially,
    Aaron



    Keep Our Board Clean!
    • Please Mark your thread "Solved" if you get an acceptable response (under thread tools).
    • Enclose your code in VBA tags then it will be formatted as per the VBIDE to improve readability.

  6. #6
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Why do you have 2, there is only one last duplicate value.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  7. #7
    Knowledge Base Approver VBAX Master Oorang's Avatar
    Joined
    Jan 2007
    Posts
    1,135
    Location
    Good question Missed that detail
    Cordially,
    Aaron



    Keep Our Board Clean!
    • Please Mark your thread "Solved" if you get an acceptable response (under thread tools).
    • Enclose your code in VBA tags then it will be formatted as per the VBIDE to improve readability.

  8. #8
    Mac Moderator VBAX Guru mikerickson's Avatar
    Joined
    May 2007
    Location
    Davis CA
    Posts
    2,778
    This array formula modification of Oorang's formula will return the row number of the one last duplicated value

    =MAX(--(COUNTIF(B1:B1000,B1:B1000)>1)*ROW(B1:B1000))

    =INDEX(B:B,rowNumber,1) will return the value itself.

    (Array formulas are confirmed with Ctrl-Shift-Enter (Cmd-Return for Mac))

Posting Permissions

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