Page 3 of 3 FirstFirst 123
Results 21 to 28 of 28

Thread: Remove Duplicates From Across Multipe Columns In A Single WorkSheet

  1. #21
    Senior Member
    Join Date
    Jun 2012
    Posts
    337
    Rep Power
    13
    assumptions:

    - data in sheet1
    - row 1 doesn't contain fieldnames
    - no empty rows in the usedrange
    - 17 columns that contain data

    Code:
    Sub M_snb()
      sn=sheet1.cells(1).currentregion.resize(,17)
    
      with createobject("scripting.dictionary")
         for j=1 to ubound(sn)
           .item(join(application.index(sn,j,0)))=application.index(sn,j,0)
         next
         sheet2.cells(1).resize(.count,17)=application.index(.items,0,0)
      end with
    End Sub
    or another method

    Code:
    Sub M_snb()
      sn=sheet1.cells(1).currentregion.resize(,17)
      c00=""
    
     for j=1 to ubound(sn)
        if instr(c00 & "|" ,"|" & application.index(sn,j,0) & "|") then 
         sn(j,1)=""
        else
         c00=c00 & "|" & application.index(sn,j,0)
        end if
      next
    
      sheet1.cells(1).currentregion.resize(,17)=sn
      sheet1.columns(1).specialcells(4).entirerow.delete
    End Sub
    Last edited by snb; 10-27-2013 at 09:34 PM.

  2. #22
    Junior Member
    Join Date
    Oct 2013
    Posts
    14
    Rep Power
    0
    Hi, only got another chance to get on it.

    Unfortunately, same run-time error 14, out of string space.

  3. #23
    Junior Member
    Join Date
    Oct 2013
    Posts
    14
    Rep Power
    0
    Hi again,

    In this case both methods ended up with error code 13, type mismatch.

  4. #24
    Administrator Admin's Avatar
    Join Date
    Mar 2011
    Posts
    1,123
    Rep Power
    10
    Quote Originally Posted by cyphrevil View Post
    Hi, only got another chance to get on it.

    Unfortunately, same run-time error 14, out of string space.
    Give this a try.

    Code:
    Option Explicit
    
    Sub kTest()
        
        Dim strAll  As String
        Dim i       As Long
        Dim r       As Long
        Dim n       As Long
        Dim d       As Long
        Dim fd      As String
        Dim fn      As String
        Dim objFS   As Object
        Dim objFile As Object
        Dim adoConn As Object
        Dim adoRset As Object
        Dim Flg     As Boolean
        
        Const Block = 65000
        
        fd = Environ("temp") & "\"
        fn = "Test.txt"
        
        Set objFS = CreateObject("scripting.filesystemobject")
        
        strAll = "Temp"
        
        For i = 1 To 17
            d = 0
            n = Cells(Rows.Count, i).End(3).Row
            If n = 1 Then n = Rows.Count
            For r = 1 To n Step Block
                strAll = strAll & vbCrLf & Join(Application.Transpose(Cells(r, i).Resize(Application.Min(Block, Abs(n - d))).Value2), vbCrLf)
                d = d + Block
            Next
            If Flg Then
                Set objFile = objFS.opentextfile(fd & fn, 8)
            Else
                Set objFile = objFS.opentextfile(fd & fn, 2, 0)
                Flg = True
            End If
            objFile.write strAll
            objFile.Close
            strAll = vbNullString
        Next
        If LenB(strAll) Then
            Set objFile = objFS.opentextfile(fd & fn, IIf(Flg, 8, 2), IIf(Flg, 0, 1))
            objFile.write strAll
            objFile.Close
        End If
        
        Set adoConn = CreateObject("ADODB.Connection")
        
        adoConn.Open "Driver={Microsoft Text Driver (*.txt; *.csv)};" & _
                    "Dbq=" & fd & ";Extensions=txt;"
            
        Set adoRset = CreateObject("ADODB.Recordset")
            adoRset.Open "SELECT [Temp] FROM [" & fn & "] GROUP BY [Temp]", adoConn, 3, 1, 1
                
        d = adoRset.RecordCount
        
        ActiveSheet.UsedRange.ClearContents
        
        If d > Rows.Count Then
            i = 1
            While Not adoRset.EOF
                Cells(1, i).CopyFromRecordset adoRset, 1000000
                i = i + 1
            Wend
        Else
            Range("a1").CopyFromRecordset adoRset
        End If
        
        adoRset.Close
        adoConn.Close
        
        Kill fd & fn
        
    End Sub
    Cheers !

    Excel Range to BBCode Table
    Use Social Networking Tools If You Like the Answers !

    Message to Cross Posters

    @ Home - Office 2010/2013/2016 on Win 10 (64 bit); @ Work - Office 2016 on Win 10 (64 bit)

  5. #25
    Junior Member
    Join Date
    Oct 2013
    Posts
    14
    Rep Power
    0

    Update

    No matter what I do it keeps giving me 'file not found' error code 53.

  6. #26
    Administrator Admin's Avatar
    Join Date
    Mar 2011
    Posts
    1,123
    Rep Power
    10
    Hi

    Replace this line
    Code:
    Set objFile = objFS.opentextfile(fd & fn, 2, 0)
    with

    Code:
    Set objFile = objFS.opentextfile(fd & fn, 2, 1)
    Cheers !

    Excel Range to BBCode Table
    Use Social Networking Tools If You Like the Answers !

    Message to Cross Posters

    @ Home - Office 2010/2013/2016 on Win 10 (64 bit); @ Work - Office 2016 on Win 10 (64 bit)

  7. #27
    Junior Member
    Join Date
    Oct 2013
    Posts
    14
    Rep Power
    0
    YES, IT WORKS!!

    Runs for about 5 minutes and results with nearly 2.8mln unique cells. Had to run it few times to check if every result is identical.
    There can be no empty cells in any of the columns though - I mean until last cell used in the column.

    Thank you thank you thank you

  8. #28
    Administrator Admin's Avatar
    Join Date
    Mar 2011
    Posts
    1,123
    Rep Power
    10
    You are welcome !
    Cheers !

    Excel Range to BBCode Table
    Use Social Networking Tools If You Like the Answers !

    Message to Cross Posters

    @ Home - Office 2010/2013/2016 on Win 10 (64 bit); @ Work - Office 2016 on Win 10 (64 bit)

Similar Threads

  1. Find Duplicates, 2 Columns, Different Worksheets
    By ghendi in forum Excel Help
    Replies: 14
    Last Post: 07-17-2013, 04:26 AM
  2. Remove Special Characters From Text Or Remove Numbers From Text
    By Excel Fox in forum Excel and VBA Tips and Tricks
    Replies: 5
    Last Post: 05-31-2013, 04:43 PM
  3. Print Nth Worksheet To Mth Worksheet using VBA
    By Ryan_Bernal in forum Excel Help
    Replies: 2
    Last Post: 02-28-2013, 06:57 PM
  4. Converge Data From Multiple Columns To Single Column
    By ayazgreat in forum Excel Help
    Replies: 3
    Last Post: 12-14-2012, 10:55 PM
  5. Detect Duplicates In Named Ranges With Cross Check
    By Yegarboy in forum Excel Help
    Replies: 3
    Last Post: 10-09-2012, 11:02 AM

Posting Permissions

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