Consulting

Results 1 to 6 of 6

Thread: Delete the duplicate value/cell in selected range

  1. #1
    VBAX Regular naris's Avatar
    Joined
    Jul 2008
    Posts
    34
    Location

    Delete the duplicate value/cell in selected range

    Dear all my friends in this forum,

    I need your help to solve my problem, I want delete the duplicate value/cell in selected range.

    Thanks.
    Naris

  2. #2
    Knowledge Base Approver VBAX Guru GTO's Avatar
    Joined
    Sep 2008
    Posts
    3,368
    Location
    Greetings Naris,

    Presuming you mean to delete both of the duplicate values, try:

    In a Standard Module:
    [vba]
    Option Explicit

    Sub DelDups()
    Dim _
    arySelection As Variant, _
    aryTemp() As Boolean, _
    x As Long, _
    y As Long


    If Selection.Count > 1 Then

    arySelection = Selection.Value

    ReDim aryTemp(1 To UBound(arySelection, 1), 1 To UBound(arySelection, 2))

    For x = 1 To UBound(arySelection, 1)
    For y = 1 To UBound(arySelection, 2)
    If Application.WorksheetFunction _
    .CountIf(Selection, arySelection(x, y)) > 1 Then

    aryTemp(x, y) = True
    End If
    Next
    Next
    For x = 1 To UBound(arySelection, 1)
    For y = 1 To UBound(arySelection, 2)
    If aryTemp(x, y) = True Then
    arySelection(x, y) = Empty
    End If
    Next
    Next

    Selection.Value = arySelection
    End If
    End Sub
    [/vba]

    Hope that helps,

    Mark

  3. #3
    VBAX Regular naris's Avatar
    Joined
    Jul 2008
    Posts
    34
    Location
    Thanks for your quick response & help, it will helpful.

    Naris

  4. #4
    Knowledge Base Approver VBAX Guru GTO's Avatar
    Joined
    Sep 2008
    Posts
    3,368
    Location
    Happy to help

    If that does the trick, you can mark the thread as solved using the Thread Tools button right above your first post

    Mark

  5. #5
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,064
    Location
    I may be reading this wrong Mark, but my impression was that the OP is looking to delete the duplicate cell within the range ( as in the recurring cell value rather than both values). But time will tell if I'm wrong.
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

  6. #6
    Knowledge Base Approver VBAX Guru GTO's Avatar
    Joined
    Sep 2008
    Posts
    3,368
    Location
    Hi Ted

    Hmmm... I may have misread #3.

    @Naris:

    Did that do the trick, or were we looking to leave one of ea given val?

    Mark

Posting Permissions

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