Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #17  
Old 12-14-2017, 07:38 AM
NoSparks NoSparks is offline Macro to check against Columns & Delete Duplicates Windows 7 64bit Macro to check against Columns & Delete Duplicates Office 2010 64bit
Excel Hobbyist
 
Join Date: Nov 2013
Location: British Columbia, Canada
Posts: 842
NoSparks is a glorious beacon of lightNoSparks is a glorious beacon of lightNoSparks is a glorious beacon of lightNoSparks is a glorious beacon of lightNoSparks is a glorious beacon of light
Default

@ cjamps
does this array approach work with the data you can't post or am I wasting my time trying to help ?
Code:
Function onlynumbers(ByVal ref As String)
' remove all but digits from string
Dim rx As Object
Set rx = CreateObject("VBScript.RegExp")
With rx
    .Pattern = "\D"
    .Global = True
    onlynumbers = .Replace(ref, "")
End With
End Function


Sub cjamps_Delete_Duplicates()

    Dim lr As Long, i As Long, j As Long, k As Long, x As Long
    Dim ws As Worksheet, ray1, ray2
    Dim dic As Object
    
Set ws = ThisWorkbook.Sheets("Sheet1")
Set dic = CreateObject("scripting.dictionary")

Application.ScreenUpdating = False

With ws
    lr = .Columns("A:C").Cells.Find(What:="*", SearchDirection:=xlPrevious, SearchOrder:=xlByRows).Row
    
    ray1 = .Range("A2:C" & lr).Value
        For i = 1 To UBound(ray1, 1)
            For j = 1 To UBound(ray1, 2)
                ray1(i, j) = onlynumbers(ray1(i, j))
                'populate dictionary
                If ray1(i, j) <> "" Then dic(ray1(i, j)) = True
            Next j
        Next i
        
    ray2 = .Range("D2", ws.Range("D" & Rows.Count).End(xlUp)).Value
        For i = 1 To UBound(ray2, 1)
            ray2(i, 1) = onlynumbers(ray2(i, 1))
        Next i
    
    'check dictionary for ray2 elements
    'MsgBox LBound(ray2) & vbLf & UBound(ray2)
    For k = 1 To UBound(ray2, 1)
        If dic.exists(Right(ray2(k, 1), 10)) Then
            ray2(k, 1) = ""
        Else
            dic(Right(ray2(k, 1), 10)) = True
            ray2(k, 1) = Format(ray2(k, 1), "000-000-0000")
        End If
    Next k
    
    'clear original col D
    .UsedRange.Columns("D").Offset(1).ClearContents
    'write ray2 to column D, omitting blanks
    x = 2
    For i = 1 To UBound(ray2, 1)
        If ray2(i, 1) <> "" Then
            .Cells(x, 4) = ray2(i, 1)
            x = x + 1
        End If
    Next i
End With
Application.ScreenUpdating = True
End Sub
Attached Files
File Type: xlsm cjamps_MSOForum_v3.xlsm (24.7 KB, 9 views)
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro to check against Columns &amp; Delete Duplicates VBA: Delete duplicates in each row bandaanders Excel Programming 2 09-02-2015 08:15 AM
Macro to check against Columns &amp; Delete Duplicates Excel vba to check to check if two columns are empty subspace3 Excel Programming 5 07-09-2015 04:45 PM
Macro to keep first instance and remove duplicates in certain column zhead Excel 2 03-18-2015 10:16 AM
Macro to check against Columns &amp; Delete Duplicates find and delete duplicates rcVBA Word VBA 4 05-15-2013 03:08 PM
Macro to check against Columns &amp; Delete Duplicates Deleting Duplicates in Macro jillapass Excel Programming 1 01-11-2012 10:02 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 02:45 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft