Consulting

Results 1 to 7 of 7

Thread: Delete duplicate value for same date and other look up value.

  1. #1

    Delete duplicate value for same date and other look up value.

    Dear All,


    I was trying to delete the duplicate values which comes from XLOOKUP formula but is same for several dates.
    For example, in attached file, In column C, HCFT comes from the Xlookup on Column B.
    However, the value in Column C is repetitive for the same date.
    I am looking for a VBA to remove the repetitive HCFT only (not all the rows) for the same date and Vehicle number.
    My objective is to remove the colored values using VBA in Column C since those are equals to same date same vehicle.
    Could you please help me to sort the problem?
    Thanks in advance.


    Shotez
    Attached Files Attached Files

  2. #2
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,875
    try:
    Sub blah()
    ActiveSheet.Range("$A$1").CurrentRegion.Resize(, 3).RemoveDuplicates Columns:=Array(1, 2, 3), Header:=xlYes
    End Sub
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  3. #3
    Quote Originally Posted by p45cal View Post
    try:
    Sub blah()
    ActiveSheet.Range("$A$1").CurrentRegion.Resize(, 3).RemoveDuplicates Columns:=Array(1, 2, 3), Header:=xlYes
    End Sub
    Hi P45cal,
    Thanks for your effort. But I was looking for something else.
    I mentioned that I need to remove the duplicate values in HCFT column and other cell cell and rows will remain as it is.
    Hope I can briefed well.

    Shotez

  4. #4
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,875
    Change the formula in C2 to:
    =IF(AND(B2=B1,A2=A1),"",XLOOKUP(B2,$F$2:$F$6,$G$2:$G$6))
    and copy down.
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  5. #5
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,726
    Location
    This?

    Capture.JPG


    Option Explicit
    
    
    Sub RemoveHCFT()
        Dim i As Long
        
        With Worksheets("Sheet4").Cells(1, 1).CurrentRegion
            For i = .Rows.Count To 3 Step -1
                If .Cells(i, 1).Value = .Cells(i - 1, 1).Value And _
                    .Cells(i, 2).Value = .Cells(i - 1, 2).Value And _
                    .Cells(i, 3).Value = .Cells(i - 1, 3).Value Then
                    .Cells(i, 3).ClearContents
                End If
            Next i
        End With
    End Sub
    Attached Files Attached Files
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  6. #6
    Hi Paul Hoosler,
    Exactly, you are on point. Thanks a lot for your effort and time.


    Shotez

  7. #7
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,726
    Location
    NP

    Not the most efficient approach, but probably the simplest one
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

Tags for this Thread

Posting Permissions

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