remove duplicate value within a row but keep first found value and remove the rest
Hi MVPs
i currently working on a list which contains several data horizontally, it contain some duplicate value within a row. i want to remove all duplicate but keep first found value and not delete entire row. since it's over 9000 rows, it would be painfull to do it manually
please your kind help and attached file for you to have clarity about what my problem is
None of us get paid for helping you... we do this for fun. So DON'T FORGET to say "Thank You" to all who have freely given some of their time to help YOU.
Temporary addition of accented to illustrate ongoing problem to the TT: L? fh?ile P?draig sona dhaoibh
Re: remove duplicate value within a row but keep first found value and remove the rest
Another option
Assuming your source sheet is Sheet1, the result will be in Sheet2.
PHP Code:
Option Explicit Sub dup() Dim lr&, i&, j&, k&, rng, dic As Object, sp, s, res(), c As Boolean With Sheets("Sheet1") lr = .Cells(Rows.Count, "A").End(xlUp).Row ' last used row of col A rng = .Range("A2:M" & lr).Value ' expand range into actual range ReDim res(1 To UBound(rng), 1 To UBound(rng, 2)) End With For i = 1 To UBound(rng) Set dic = CreateObject("Scripting.Dictionary") k = 0 For j = 1 To UBound(rng, 2) If Not IsEmpty(rng(i, j)) Then c = False: sp = Split(rng(i, j), ",") For Each s In sp If Not dic.exists(s) Then dic.Add s, "" c = True End If Next If c Then k = k + 1: res(i, k) = rng(i, j) End If Next Next Sheets("sheet2").Activate Range("A2:XX100000").ClearContents Range("A2").Resize(UBound(res), UBound(res, 2)).Value = res End Sub
tested to my personal laptop which using 365 and worked as well, even currently i'm working at company that still using 2016, please accept the star for you
Bookmarks