+ Reply to Thread
Results 1 to 8 of 8

function to remove duplicates from different sheets

Hybrid View

  1. #1
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,892

    function to remove duplicates from different sheets

    Hello everybody
    Is there a UDF function that extract distinct values from different sheets..?
    Say I have duplicate values in Range ("A1:A20") in two different sheets and I want to extract the distinct values from the two lists ..
    Is there a function that can do that task?

  2. #2
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,892

    Re: function to remove duplicates from different sheets

    I have this code that do that task of extracting unique lists from multi sheets..
    Sub UniqueId()
    For j = 2 To Sheets.Count
        With Sheets(j)
        Set deb = .Range("G4:G" & .Range("G" & .Rows.Count).End(xlUp).Row)
            For i = 1 To deb.Rows.Count
                If InStr(raj & ",", "," & deb(i, 1) & ",") = 0 Then raj = raj & "," & deb(i, 1)
            Next i
        End With
    Next j
     
        roy = Split(Mid(raj, 2), ",")
        Sheets(1).Range("C4").Resize(UBound(roy) + 1) = Application.Transpose(roy)
    End Sub
    But it extracts a blank cell which is considered as a unique value.. I want to get rid of that blank unique value

  3. #3
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: function to remove duplicates from different sheets

    Sub UniqueId()
    For j = 2 To Sheets.Count
        With Sheets(j)
        Set deb = .Range("G4:G" & .Range("G" & .Rows.Count).End(xlUp).Row)
            For i = 1 To deb.Rows.Count
                If deb(i, 1) <> "" Then
                  If InStr(raj & ",", "," & deb(i, 1) & ",") = 0 Then raj = raj & "," & deb(i, 1)
                End If
            Next i
        End With
    Next j
     
        roy = Split(Mid(raj, 2), ",")
        Sheets(1).Range("C4").Resize(UBound(roy) + 1) = Application.Transpose(roy)
    End Sub

  4. #4
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,892

    Re: function to remove duplicates from different sheets

    Great Great Thank you very much
    Is there a function that I can use to do the same by selecting my ranges from different sheets?

  5. #5
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,892

    Re: function to remove duplicates from different sheets

    Is there a function? or I have to use codes ?

  6. #6
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,892

    Re: function to remove duplicates from different sheets

    Okay
    As for this wonderful code
    I want to specify two sheets only sheet named (Result1) and sheet named (Export1).. Can I edit the code to be able to deal these two sheets?
    Sub UniqueId()
    For j = 2 To Sheets.Count
        With Sheets(j)
        Set deb = .Range("G4:G" & .Range("G" & .Rows.Count).End(xlUp).Row)
            For i = 1 To deb.Rows.Count
                If deb(i, 1) <> "" Then
                  If InStr(raj & ",", "," & deb(i, 1) & ",") = 0 Then raj = raj & "," & deb(i, 1)
                End If
            Next i
        End With
    Next j
     
        roy = Split(Mid(raj, 2), ",")
        Sheets(1).Range("C4").Resize(UBound(roy) + 1) = Application.Transpose(roy)
    End Sub

  7. #7
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: function to remove duplicates from different sheets

    Hi YasserKhalil,
    maybe so
    Dim v
    For Each v In Array("Result1", "Export1")
        With Sheets(v)
            Set deb = .Range("G4:G" & .Range("G" & .Rows.Count).End(xlUp).Row)
            For i = 1 To deb.Rows.Count
                If deb(i, 1) <> "" Then
                    If InStr(raj & ",", "," & deb(i, 1) & ",") = 0 Then raj = raj & "," & deb(i, 1)
                End If
            Next i
        End With
    Next v
    ...

  8. #8
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,892

    Re: function to remove duplicates from different sheets

    Thank you very much for great help in this great forum

+ 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. How to remove duplicates AND values that have duplicates?
    By bachfantasia in forum Excel General
    Replies: 9
    Last Post: 05-13-2014, 07:05 PM
  2. Replies: 1
    Last Post: 10-23-2012, 09:12 AM
  3. Replies: 5
    Last Post: 02-28-2012, 02:52 PM
  4. Need VBA code to remove entries if there are duplicates (remove them totally)
    By BrandonFromSingapore in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-13-2012, 12:50 AM
  5. Replies: 2
    Last Post: 03-20-2011, 11:19 AM

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